Amit
asked on
script to grab ip addresses
Hi,
I need to find the ip addresses of almost 50 machines. So I need to open a dos window and
issue ping hostname and then I get the reply form where I can get the ip address
like this
__________________________ __________ __________ __________ ________
C:\>ping hostname
Pinging HOSTNAME.corp.EXAMPLE.com [10.555.55.55] with 32 bytes of data:
Reply from 10.555.55.55: bytes=32 time=2ms TTL=122
Reply from 10.555.55.55: bytes=32 time=3ms TTL=122
Reply from 10.555.55.55: bytes=32 time=6ms TTL=122
Reply from 10.555.55.55: bytes=32 time=6ms TTL=122
Ping statistics for 10.555.55.55:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 2ms, Maximum = 6ms, Average = 4ms
__________________________ __________ __________ __________ ________
Now could somebody write a perl script for me which will be
perl inputfilename outputfilename
int the input file I will put all the hostnames
In the output file it should have the output as
hostname ipaddress
hostname 10.555.55.55
I need to find the ip addresses of almost 50 machines. So I need to open a dos window and
issue ping hostname and then I get the reply form where I can get the ip address
like this
__________________________
C:\>ping hostname
Pinging HOSTNAME.corp.EXAMPLE.com [10.555.55.55] with 32 bytes of data:
Reply from 10.555.55.55: bytes=32 time=2ms TTL=122
Reply from 10.555.55.55: bytes=32 time=3ms TTL=122
Reply from 10.555.55.55: bytes=32 time=6ms TTL=122
Reply from 10.555.55.55: bytes=32 time=6ms TTL=122
Ping statistics for 10.555.55.55:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 2ms, Maximum = 6ms, Average = 4ms
__________________________
Now could somebody write a perl script for me which will be
perl inputfilename outputfilename
int the input file I will put all the hostnames
In the output file it should have the output as
hostname ipaddress
hostname 10.555.55.55
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello Perl Diver,
I issued
perl C:\Perl\scripts\ipaddresse s.pl C:\Perl\scripts\hostname.t xt
but nothing seems to be working. I am not familiar with perl, could you please modify this code so that it can take a file as input
thanks
I issued
perl C:\Perl\scripts\ipaddresse
but nothing seems to be working. I am not familiar with perl, could you please modify this code so that it can take a file as input
thanks
what is ipaddresses.pl, post the code.
ASKER
I copied the code you posted in a file and named it ipaddresses.pl . So the code inside it is
my @p = grep{!/^\s*$/} qx/ping hostname -n 1/;
my ($h,$i) = $p[0] =~ /pinging\s+(\S+)\s+\[([^\] ]+)]/i;
print "$h $i\n";
my @p = grep{!/^\s*$/} qx/ping hostname -n 1/;
my ($h,$i) = $p[0] =~ /pinging\s+(\S+)\s+\[([^\]
print "$h $i\n";
What does the file you want to use as input look like?
use Net::Nslookup;
foreach $host (<>) {
print $host, nslookup $host;
}