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
https://forums.phpfreaks.com/topic/218013-how-to-ping/
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
https://forums.phpfreaks.com/topic/218013-how-to-ping/#findComment-1131520
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.