I tried this but it kept timing out when i added an IP ad the $hostname, how can i do this with IP addresses?

    Hmm, i guess i don't understand your problem. Please explain...

      All i want to do is ping the IP numbers of the servers I have on the lan, and give them a image for whatever status they are?

        My problem is that its IP addresses i need to ping.

        <?
        function ping($host) {
        echo 'HOSTNAME: <a class="text" href="http://' . $host . '">' . $host . '</a><br>';

        $ip = gethostbyname($host);
        echo 'IP: '. $ip . '<hr>';
        $result = ping -c 1 $ip;

        $a = strpos($result, "time=");

        $b = strpos($result, " ms");

        if (!$a || !$b) {

        return FALSE;

        }

        $a = $a+5;

        $r = substr($result, $a, $b-$a);

        return $r;

        }

        $hostname = 'www.phpbuilder.com';
        $ping = ping($hostname);
        if(!$ping) echo 'Ping timed out.'; else
        echo 'ping time: ' . $ping . ' ms';

        I dont have a domain name like above, just an IP address. So when I try it I assume it tries to convert the hostname into an IP and it fails.

        Any other ideas?

          <? 
          function ping($ip) { 
          echo 'IP: '. $ip . '<hr>'; 
          $result = `ping -c 1 $ip`; 
          $a = strpos($result, "time="); 
          $b = strpos($result, " ms"); 
          if (!$a || !$b) { 
          return FALSE; 
          } 
          $a = $a+5; 
          $r = substr($result, $a, $b-$a); 
          return $r; 
          } 
          
          $ip = '192.168.0.1';
          $ping = ping($hostname); 
          if(!$ping) echo 'Ping timed out.'; else 
          echo 'ping time: ' . $ping . ' ms'; 
          

          Like this?? Just remove the gethostbyname()....

            Keep getting Ping timed out.

            $ping = ping($hostname);

            Wheres $hostname defined?

            should it be

            ping($ip);

            ??

            Even if it is i still get ping timed out...

              Yeah ofcourse it should be ping($ip). But when it times out, are you sure you're able to ping that ip address from your server?? You cannot ping a local ip from the internet ofcourse... Try pinging an ip you know for sure it exists and it should work. I think the fault is not in the script but somewhere else.

                I did, i changed it to 192.168.200.1 and the webserver is on the same network 192.168.200.240, and it can ping this address normally. Its an NT box running apache.

                  Than i don't know. The script works as you can see, so the error is somewhere in your network or configuration.

                    If i change this line

                    $result = ping -n 1 $ip;

                    to

                    $result = system ("ping -n 1 $ip");

                    I get a response

                    Pinging 192.168.200.1 with 32 bytes of data: Reply from 192.168.200.1: bytes=32 time<10ms TTL=255 Ping timed out.

                    I think theres a problem with this line

                    $result = ping -n 1 $ip;

                      So what is the final, confirmed as working, code that ya'll are using?

                        bump ... are we allowed to do this? heh
                        hellllllp guys

                          I cant get it to work properly.

                          This line is the one im having trouble with.

                          $result = system ("ping -n 1 $ip");

                            Write a Reply...