• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 849
  • Last Modified:

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




0
anshuma
Asked:
anshuma
  • 3
  • 2
1 Solution
 
mish33Commented:
You don't need ping. Install http://search.cpan.org/CPAN/authors/id/D/DA/DARREN/Net-Nslookup-1.16.tar.gz

use Net::Nslookup;
foreach $host (<>) {
  print $host, nslookup $host;
}
0
 
Perl_DiverCommented:
basci concept if you use the DOS ping command:

my @p = grep{!/^\s*$/} qx/ping hostname -n 1/;
my ($h,$i) = $p[0] =~ /pinging\s+(\S+)\s+\[([^\]]+)]/i;    
print "$h $i\n";
0
 
anshumaEngineeringAuthor Commented:
Hello Perl Diver,

I issued

perl C:\Perl\scripts\ipaddresses.pl C:\Perl\scripts\hostname.txt

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
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Perl_DiverCommented:
what is ipaddresses.pl, post the code.
0
 
anshumaEngineeringAuthor Commented:
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";
0
 
Perl_DiverCommented:
What does the file you want to use as input look like?
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now