Jump to content

How to Ping


Joshua F

Recommended Posts

How Would I ping an IP Address with Php.

 

I am planning on using ping so that it pings a server ip, and if it matches the ip that the server is hosted on, then it will activate the profile.

 

EG: Ping: MagicPkz.no-ip.org

Comes out with my IP(70.177.**.***)

Now I go to a page, it checks to see if MagicPkz.no-ip.org matches up to my IP, and if it does, it activates the profile, if it doesn't it gives an error.

Link to comment
Share on other sites

A short Google later and *poof*:

 

ob_start();
system("ping " . escapeshellarg($site));
print ob_end_flush();

Not totally cross-platform compatible, but you could also try using cURL:

 

function curlTest2($url) {

        clearstatcache();

        $return = '';

        if(substr($url,0,4)!="http") $url = "http://".$url;

        $userAgent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)';

        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_NOBODY, 1);
        curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 15);
        curl_setopt($ch, CURLOPT_FAILONERROR, 1);
        curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);

        $execute = curl_exec($ch);

        // Check if any error occured
        if(!curl_errno($ch)) {
                $bytes          = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
                $total_time = curl_getinfo($ch, CURLINFO_TOTAL_TIME);
                $return = 'Took ' . $total_time . ' / Bytes: '. $bytes;        
        } else {
                $return = 'Error reaching domain';
        }
        curl_close($ch);

        return $return;

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.