Joshua F Posted November 7, 2010 Share Posted November 7, 2010 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. Quote Link to comment Share on other sites More sharing options...
Joshua F Posted November 7, 2010 Author Share Posted November 7, 2010 Bump. Quote Link to comment Share on other sites More sharing options...
mattal999 Posted November 7, 2010 Share Posted November 7, 2010 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; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.