Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Ping a Server

by damianpadden (Initiate)
on Apr 28, 2004 at 08:10 UTC ( #348748=perlquestion: print w/replies, xml ) Need Help??

damianpadden has asked for the wisdom of the Perl Monks concerning the following question:

I am wanting to get the ip address of all my servers. I want to run a perl script from my local workstation to get the ip address of servers from a list I have created. I have search for "getting a ip address" but nothing in a remote way is if the search results I get back

Replies are listed 'Best First'.
Re: Ping a Server
by AcidHawk (Vicar) on Apr 28, 2004 at 08:25 UTC
    What have you tried?

    What does your list of servers look like?

    Post some code so we can look and make suggestions.

    Update: Assuming you file has a server name on each line try the following..

  • open the Server List file
  • read in line by line
  • for each line/servername ping the server (either OS ping with $result = `ping $_`;then do some regex on the $result or look at Net::Ping)
  • close Server List file
  • The code below works for me using Net::Ping PS I havent done the open file and read in a list etc.

    #! /usr/bin/perl use strict; use warnings; use Net::Ping; my ($host,$rtt,$ip); my @host_array = ("OSSTNGMCN01", "OSSTNGMCN04", "PROJECTX99"); my $p = Net::Ping->new("syn"); $p->{port_num} = getservbyname("http", "tcp"); foreach $host (@host_array) { $p->ping($host); } while (($host,$rtt,$ip) = $p->ack) { print "HOST: $host [$ip] ACKed in $rtt seconds.\n"; }
    -----
    Of all the things I've lost in my life, its my mind I miss the most.
Re: Ping a Server
by OzzyOsbourne (Chaplain) on Apr 28, 2004 at 12:40 UTC
    my $IP=&resolve('Server'); print "$IP\n"; sub resolve(){ my $check=join('.',(unpack("C4", gethostbyname($_[0])))); return $check; }
Re: Ping a Server
by mce (Curate) on Apr 28, 2004 at 08:28 UTC
    Hi,

    What do you mean by server?
    Is it windows and you mean the AD server?
    Is it the print server, logon server, etc... ?
    In the Win32::NetAdmin package, there are several methods for locating your windows server, is that is what you want, and once located use DNS to find the ipaddress: gethostbyname


    ---------------------------
    Dr. Mark Ceulemans
    Senior Consultant
    BMC, Belgium
Re: Ping a Server
by TomDLux (Vicar) on Apr 28, 2004 at 16:30 UTC

    'getting an IP address' == 'using DNS to determine the IP number associated with a name'.

    I use nslookup, but that tells me it is obsolete and I should use dig or host. You may want a different client on MS.

    --
    TTTATCGGTCGTTATATAGATGTTTGCA

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://348748]
Approved by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2022-10-06 01:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (26 votes). Check out past polls.

    Notices?