in reply to Pinging.

Try with Net::Ping, here is some code from the man page:

use Net::Ping; $p = Net::Ping->new(); print "$host is alive.\n" if $p->ping($host); $p->close();

Ciao, Valerio

Replies are listed 'Best First'.
Re: Re: Pinging.
by blackadder (Hermit) on Aug 07, 2002 at 13:36 UTC
    You can use AdminMisc's GetHostAddress($DNS_Name) this will supply you with the IP address.

    I would keep all the servers host names in a text file list. Then I read the complete list into an array like this

    open(srv,"c:/server.txt")|| die "$^E\n"; chomp ( my @servers =<srv>);
    then foreach item in the list get the Ip address.
    Foreach my $srv (sort @servers){ my $ip = Win32::AdminMisc::GetHostAddress($srv); print "\nhost: $srv\tIp Address: $ip\n";}
    Cheers,...Blackadder
      hi there. is this script for win32? will this script do the required as described above? what i realy think i need it to do is telnet my servers ip address on port 25 and if it recieves a response (i.e it doesn't time out) then all is ok, else display an error message
        Have a look at this write up I had a week back. You could use just the check_host procedure if you want. It is platform independant. I'm using it on Win32 at the moment, and also had the same code execute on AIX 4.3.3 with NO problem. The script essentally does a TCP connect to the machine specified.
Re: Re: Pinging.
by Anonymous Monk on Aug 07, 2002 at 13:11 UTC
    sorry formy stupidity, but how would you add a 'host is dead' print to this script? thanks
      How would you add a 'host is dead' print to this script?

      Hi Anonymous Monk.
      #!/usr/bin/perl -w use strict; use Net::Ping; my $host; print "Host to ping? "; chomp( $host = <STDIN> ); my $p = Net::Ping->new(); if( $p->ping($host) ) { print "$host is alive!\n"; } else { print "$host appears to be dead.\n"; } $p->close();

      Hope this helps,
      -Katie.
      aaarrrgghh, now i have a real problem. I forgot that the firewall between my server and the outside world drops ping requests. is there any way to check to see if my server is alive using a TCP connect method to see if it recieves a response form a port? i.e connect to port 25 and see if my smtp server responds? thanks

        You can do as follow:

        use Net::SMTP; @verify = ('smtp.host1.tld', 'smtp.host2.tld'); foreach $host (@verify) { $smtp = Net::SMTP->new($host); if (ref($smtp)) { print $smtp->banner(); } else { print "failed $host!\n"; } }

        This kind of check probably is better than pinging a host, but still doesn't tell you what is happening. A better solution would be to download a file from every remote host to be checked; if you can make these files contain some useful informations, like uptime, load average and disk usage, you can check what is happening and prevent also some kind of errors (i.e. disk full).
        You can generate those files automatically via a cron job and download them via HTTP or FTP, as you prefer.

        Ciao, Valerio