PHP ping to get response with the ip address -


i'm trying ping ip address test ip address whether available or not. having trouble on using fsockopen function. had research on using 'ping','exec' function none of them seem workable.

here code test ip address:

<?php     $ipaddress = array("192.168.1.1","192.168.1.67");     $kiosk = array("kuantan (35)","utc kuantan (36)");      $checkcount = 0;     foreach(array_combine($ipaddress,$kiosk) $items => $kiosk){         $fp = @fsockopen($items,80,$errno,$errstr,1);          if(is_resource($fp)){             if($fp) {                  $status=0;                  fclose($fp);                  echo 'success<br/>';              }         }         else{             echo 'failed<br/>';           }      } ?> 

both ip address can ping cmd prompt. 192.168.1.67 lead me 'failed', 192.168.1.1. or 127.0.0.1 showing me 'success'. there wrong?

your code not pinging tries open tcp connection on port 80. ping command uses icmp packets, 192.168.1.67 not accepting connections on port 80.

following chat catalyst here sample code send 2 packets , wait 2 seconds response. $retval 0 on success, 1 on packet loss, 2 on other error. on linux, windows command parameters bit different should able change it.

<? // unset variables first avoid mixing results previous calls $retval=-1; $output=array(); exec("ping 127.0.0.1 -c2 -w2 2>&1",$output,$retval); echo "return code: ".$retval."<br>\n"; echo implode("<br>\n",$output); ?> 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -