Menu

How to Monitor ICMP/Ping

2014-10-02
2016-08-09
  • aditya pramana putra

    hy, i have installed n running well.
    but i dont know how to monitor type ICMP or ping.
    or this php server monitor dont have feature ping right?

    thanks

     
  • NCMarc

    NCMarc - 2014-11-10

    agreed, need a ping type of monitor. I'd also like to see a DNS monitor where it will monitor and expect a certain IP address in the result, so we know its working or if the IP suddenly changes.

     
  • NCMarc

    NCMarc - 2014-11-10

    I love the product so far. If i have time, I will attempt to add these types into the product. I am not the best with PHP coding, I'm really good at other languages though.

     
  • Nathan

    Nathan - 2014-12-24

    I agree a ping monitor or DNS monitor would be great... I am trying to use this program to monitor my router uptime but I'm having issues getting it to work right... works great for general websites but for securely logged in network equipment seems to not be the best... a ping monitor would be a great option!

     
  • BeSch

    BeSch - 2015-01-15

    First of all: phpservermon rocks! I do really love that tool - great work!

    Yes, Ping Monitor is the No.1 I would like to have
    Also some additional Tools like DNS lookup, WHOIS, Traceroute, MTR etc. would be great.
    Is there an easy way to add an additional Menuitem (e.g. Tools) and add those functions?

    best regards

     
    • insuman

      insuman - 2015-03-05

      AFTER 3 HOURS FINALLY GET A SOLUTION TO PING SERVER WITH PORT 1 ....

      open StatusUpdater.class.php inside function updateService at the first line add this :

      if (($this->server['port'])==1) {
      $timeout = 5;
      / ICMP ping packet with a pre-calculated checksum /
      $package = "\x08\x00\x7d\x4b\x00\x00\x00\x00PingHost";
      $socket = socket_create(AF_INET, SOCK_RAW, 1);
      socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $timeout, 'usec' => 0));
      socket_connect($socket, $this->server['ip'], null);
      $ts = microtime(true);
      socket_send($socket, $package, strLen($package), 0);
      if (socket_read($socket, 255)) {
      $status = true;
      } else {
      //check error -- echo socket_last_error() . ' '. socket_strerror(socket_last_error());
      $status = false;
      }
      $this->rtime = (microtime(true) - $starttime);
      socket_close($socket);
      } else

      //rest of code

      {

      now add a server ip with port =1 and you will be able to ping it

      remember for win7 you must execute as admin you have to do this :

      Command Prompt > (Run as administrator)
      net user administrator /active:yes

      you have to change also response time second to milisecond

       
      • rnovo1983

        rnovo1983 - 2015-03-28

        Nice, insuman a ping solution is the only thing I really need to monitor my servers status. I did the change to the funtion update Service, but im getting white screen every time run update on the app.

         
  • rnovo1983

    rnovo1983 - 2015-03-28

    Hi, I just did this but nothing happens I got a black screen when running the update. I am windows 8 pro, where do I change "you have to change also response time second to milisecond"?.

     
  • Michele Mariotti

    Thanks insuman ...

    for other with white screen problem ... the complete function code:

        protected function updateService($max_runs, $run = 1) {
    
            if (($this->server['port']) == 1) {
                /* timeout min: 5 sec */
                $timeout = ($this->server['timeout'] < 5 ? 5 : $this->server['timeout']);
                /* save response time */
                $starttime = microtime(true);
                /* ICMP ping packet with a pre-calculated checksum */
                $package = "\x08\x00\x7d\x4b\x00\x00\x00\x00PingHost";
    
                $socket = socket_create(AF_INET, SOCK_RAW, 1);
                socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $timeout, 'usec' => 0));
                socket_connect($socket, $this->server['ip'], null);
                $ts = microtime(true);
                socket_send($socket, $package, strLen($package), 0);
    
                if (socket_read($socket, 255)) {
                    $status = true;
                } else {
                    /* store error reason */
                    $this->error = socket_last_error() .' '. socket_strerror(socket_last_error());
                    $status = false; 
                }
                $this->rtime = (microtime(true) - $starttime);
                socket_close($socket);
            } else
            //rest of code
            { 
                $errno = 0;
                // save response time
                $starttime = microtime(true);
    
                $fp = fsockopen ($this->server['ip'], $this->server['port'], $errno, $this->error, 10);
    
                $status = ($fp === false) ? false : true;
                $this->rtime = (microtime(true) - $starttime);
    
                if(is_resource($fp)) {
                    fclose($fp);
                }
            }
    
            // check if server is available and rerun if asked.
            if(!$status && $run < $max_runs) {
                return $this->updateService($max_runs, $run + 1);
            }
    
            return $status;
        }
    
     
  • Thomas Mitschke

    Thomas Mitschke - 2016-05-02

    I've a little problem. The above code works fine, but when I click on the UPDATE button in the main menu, I get a status of unreachable (the log shows: operation not permitted)
    I think I'm missing something: tried to run the vserver hosting phpservermon as root, but it doesn't solve the problem.
    The scheduled task in crontab works fine and updates the status correctly.
    Can anybody help me out?

     
    • David Dunne

      David Dunne - 2016-05-23

      Did you get this sorted?
      I have modified the script for ping to work.
      Ping monitoring works via cron but fails if using the manual update and log shows “Operation not permitted”
      PHP Server Monitor is running on FreeBSD - FAMP and in use for a number of months before patching for ping monitoring.

       
      • Kathawut Tweewarodomkul

        First time i found error like you,
        I used code of SIMONE ZANCHETTA
        2016-06-01
        and adjust code on exec as

        //-n = numeric output; -c = number of pings; -t = ttl; -W = timeout
        exec("ping -n -c 1 -t 255 -W ".$timeout. ' ' . $ip, $output, $retval);

        it worked on my Linux web hosting

         

        Last edit: Kathawut Tweewarodomkul 2016-06-15
        • David Dunne

          David Dunne - 2016-08-09

          Thank you Kathawut Tweewarodomkul

          following your advice has worked for me, including the use of your exec statement

          exec("ping -n -c 1 -t 255 -W ".$timeout. ' ' . $ip, $output, $retval);

           
  • Vander Luis

    Vander Luis - 2016-05-21

    thank you,

    All working ok with the above script. It was exactly what was missing.

    Memories...

    Vander Pereira
    Director of operations
    Teresopolis, RJ, Brazil

     
  • SIMONE ZANCHETTA

    a possibile solutions is:
    and it work well! Bye

           protected function updateService($max_runs, $run = 1) {
        if (($this->server['port']) == 1) {
            $timeout = ($this->server['timeout'] < 2 ? 2 : $this->server['timeout']);
            $starttime = microtime(true);
            $ip = $this->server['ip'];
            exec("ping -n 1 $ip 2>&1", $output, $retval);
            $ts = microtime(true);
            if ($retval != 0) { 
             $status = false;
            } 
            else 
            { 
            $status = true;
            }
            $this->rtime = (microtime(true) - $starttime);
        } else
        { 
            $errno = 0;
            $starttime = microtime(true);
            $fp = fsockopen ($this->server['ip'], $this->server['port'], $errno, $this->error, 10);
            $status = ($fp === false) ? false : true;
            $this->rtime = (microtime(true) - $starttime);
            if(is_resource($fp)) {
                fclose($fp);
            }
        }
        if(!$status && $run < $max_runs) {
            return $this->updateService($max_runs, $run + 1);
        }
        return $status;
    }
    
     

    Last edit: SIMONE ZANCHETTA 2016-06-01
  • DJAMEL

    DJAMEL - 2016-06-30

    hello Mr SIMONE ZANCHETTA thanks for your responses ,i have a problem with php server monitor i use php 5.3.5 and i installed the php server monitor on windows 7 professional edition ,i need to have the ping option for many ip adresses and when i added the code upper for getting ping i had a white screen i tried with many versions of php server monitor i tried V2.0.0 ,and 2.1.0 it"s the same result i don't have any changes according to the stat of ip adresses i added with port=1 ,can you send me the project with the ping option ,i will be verry recongnissant ,i have no base on linux that's why i use windows ,by the way i installed the cron for windows but still the same result no update for ip statements, thank you so much.

     

    Last edit: DJAMEL 2016-06-30

Log in to post a comment.