- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- nslookup on list of IPs stored in a file and stori...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-07-2009 08:17 PM
тАО09-07-2009 08:17 PM
I have a file which as some hundred's IPs stored in a text file.
The IPs are stored in following format:
192.12.10.[10|12|14|15|16|19]|10.11.21.[9|14|17|16|90]
The IPs are delimited by | pipe character.
I need a shell script which can perform nslookup on each of IP and put the resolved instance/host name in a file.
Appreciate if anyone can suggest a shell/perl script to accomplish above.
Thanks,
Shiv
Solved! Go to Solution.
- Tags:
- nslookup
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-07-2009 09:07 PM
тАО09-07-2009 09:07 PM
Re: nslookup on list of IPs stored in a file and storing resolved hostname in a file
You seem to have "|" both inside and outside []. It seems you have two patterns:
192.12.10.[10|12|14|15|16|19]
10.11.21.[9|14|17|16|90]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-07-2009 09:13 PM
тАО09-07-2009 09:13 PM
Re: nslookup on list of IPs stored in a file and storing resolved hostname in a file
Also each subnet has IPs separated by | inside []
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-08-2009 04:14 AM
тАО09-08-2009 04:14 AM
Re: nslookup on list of IPs stored in a file and storing resolved hostname in a file
Hmm, it was along day for me (teaching
HP-UX SNA II) but here is a quick
run.
a) I created a file myhosts-itrc-test.txt
that contains the following patters:
192.12.10.[10|12|14|15|16|19]|10.11.21.[9|14|17|16|90]
172.16.55.10
15.98.47.[240]
203.18.150.[1|2|21]
201.46.77.[34|95|48]|3.44.5.7
b) Then, a simple Perl script (I did not
spend much time to make it beautiful):
#!/usr/bin/perl
$MYFILE = "./myhosts-itrc-test.txt";
if ( open( MYT, "cat $MYFILE | " ) ) {
while (
$SUBN = q{};
@MYARR = ();
@MYARR2 = ();
$_ =~ s/^\s+//g;
$_ =~ s/\s+$//g;
@MYARR = split(/\|/, $_);
foreach $ent (@MYARR) {
$FHOST = q{};
if ( grep(/\[/, $ent) ) {
@MYARR2 = split(/\[/, $ent);
$SUBN = $MYARR2[0];
$FHOST = $MYARR2[1];
$FHOST =~ s/\]//g;
$FHOST =~ s/\[//g;
}
$ent =~ s/\]//g;
$ent =~ s/\[//g;
if ( grep(/\./, $ent) ) {
print "$ent\n";
}
elsif ( "$FHOST" ) {
print "$SUBN${FHOST}\n";
}
else {
print "$SUBN${ent}\n";
}
}
}
close(MYT);
}
c) Running the script reveals the following results:
192.12.10.10
192.12.10.12
192.12.10.14
192.12.10.15
192.12.10.16
192.12.10.19
10.11.21.9
10.11.21.14
10.11.21.17
10.11.21.16
10.11.21.90
172.16.55.10
15.98.47.240
203.18.150.1
203.18.150.2
203.18.150.21
201.46.77.34
201.46.77.95
201.46.77.48
3.44.5.7
The nslookup or whatever test on each
IP address is left to you as an exercise.
Cheers,
VK2COT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-08-2009 06:39 AM
тАО09-08-2009 06:39 AM
Re: nslookup on list of IPs stored in a file and storing resolved hostname in a file
Here's one solution:
# cat ./myprobe
#!/usr/bin/perl
use strict;
use warnings;
my ( $base, $subnet );
sub probe {
my ($who) = @_;
my $lookup = `nslookup $who`;
print "$who -> $1\n" if $lookup=~m{Name:\s+(.+)}i;
}
while (<>) {
chomp;
s/\|/ /g;
my @F = split /]/;
for my $range (@F) {
$range =~ s/^\s+//;
$range =~ s/\s+$//;
if ( $range =~ m{ (\d+\.\d+\.\d+\.\d+) }x ) {
probe($range);
}
( $base, $subnet ) = $range =~ m{ (\d+\.\d+\.\d+\.) \[ (.+) }x;
next unless defined $subnet;
my @FF = split / /, $subnet;
for my $node (@FF) {
probe( $base . $node ) if defined $node;
}
}
}
1;
...
Run as:
# ./myprobe inputfile
Using an 'inputfile' like:
192.12.10.[10|12|14|15|16|19]|10.11.21.[9|14|17|16|90]
10.20.30.1
10.20.30.2
10.20.30.[3]|10.21.30.3
...might produce:
*** mydns.xyz.net can't find 192.12.10.10:Non-existent host/domain
*** mydns.xyz.net can't find 192.12.10.12:Non-existent host/domain
192.12.10.14 -> ser2-v62.gw.utexas.edu
*** mydns.xyz.net can't find 192.12.10.15:Non-existent host/domain
*** mydns.xyz.net can't find 192.12.10.16:Non-existent host/domain
*** mydns.xyz.net can't find 192.12.10.19:Non-existent host/domain
*** mydns.xyz.net can't find 10.11.21.9:Non-existent host/domain
*** mydns.xyz.net can't find 10.11.21.14:Non-existent host/domain
*** mydns.xyz.net can't find 10.11.21.17:Non-existent host/domain
*** mydns.xyz.net can't find 10.11.21.16:Non-existent host/domain
*** mydns.xyz.net can't find 10.11.21.90:Non-existent host/domain
10.20.30.1 -> host1.xyz.net
10.20.30.2 -> host2.xyz.etm
10.20.30.3 -> host3.xyz.etm
10.21.30.3 -> host4.xyz.net
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-08-2009 07:12 AM
тАО09-08-2009 07:12 AM
Re: nslookup on list of IPs stored in a file and storing resolved hostname in a file
This version is cleaner and fixes a "forest-for-the-trees" error :-)
#!/usr/bin/perl
use strict;
use warnings;
my ( $base, $subnet );
sub probe {
my ($who) = @_;
my $lookup = `nslookup $who`;
print "$who -> $1\n" if $lookup=~m{Name:\s+(.+)}i;
}
while (<>) {
chomp;
s/\|/ /g;
my @F = split /]/;
for my $range (@F) {
$range =~ s/^\s+//;
$range =~ s/\s+$//;
if ( $range =~ m{ (\d+\.\d+\.\d+\.\d+) }x ) {
probe($range);
next;
}
( $base, $subnet ) = $range =~ m{ (\d+\.\d+\.\d+\.) \[ (.+) }x;
my @FF = split / /, $subnet;
for my $node (@FF) {
probe( $base . $node );
}
}
}
1;
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-08-2009 11:43 AM
тАО09-08-2009 11:43 AM
Re: nslookup on list of IPs stored in a file and storing resolved hostname in a file
I just executed your revised version of the the script but it doesn't produce any output either on screen or in any file.
Thanks,
Shiv
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-08-2009 11:49 AM
тАО09-08-2009 11:49 AM
Re: nslookup on list of IPs stored in a file and storing resolved hostname in a file
# I just executed your revised version of the the script but it doesn't produce any output either on screen or in any file.
Did you run the script specifying an input file like?
# ./myprobe file
Does your input file look like your original post suggested?
If neither of these questions are satisfied, _POST_ a _TEXT_ attachment of what your input file conists.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-08-2009 02:21 PM
тАО09-08-2009 02:21 PM
Re: nslookup on list of IPs stored in a file and storing resolved hostname in a file
$./myprog testfile
$cat testfile
192.12.10.[10|12|14|15|16|19]|10.11.21.[9|14|17|16|90]
10.20.30.1
10.20.30.2
10.20.30.[3]|10.21.30.3
=====
$cat myprog
#!/usr/bin/perl
use strict;
use warnings;
my ( $base, $subnet );
sub probe {
my ($who) = @_;
my $lookup = `nslookup $who`;
print "$who -> $1\n" if $lookup=~m{Name:\s+(.+)}i;
}
while (<>) {
chomp;
s/\|/ /g;
my @F = split /]/;
for my $range (@F) {
$range =~ s/^\s+//;
$range =~ s/\s+$//;
if ( $range =~ m{ (\d+\.\d+\.\d+\.\d+) }x ) {
probe($range);
next;
}
( $base, $subnet ) = $range =~ m{ (\d+\.\d+\.\d+\.) \[ (.+) }x;
my @FF = split / /, $subnet;
for my $node (@FF) {
probe( $base . $node );
}
}
}
1;
====
It doesn't show any output.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-08-2009 03:10 PM
тАО09-08-2009 03:10 PM
SolutionWith regard to your last post, I certainly get output:
*** xxx.yyy.com can't find 192.12.10.10:Non-existent host/domain
*** xxx.yyy.com can't find 192.12.10.12:Non-existent host/domain
192.12.10.14 -> ser2-v62.gw.utexas.edu
...
...with 'xxx.yyy'com' being my DNS server disguised.
D you have 'nslookup' in your path? If this this is indeed HP-UX it would be '/usr/bin/nslookup'. If it isn't HP-UX, modify my script to reflect the absolute path:
For example, you might need to change:
my $lookup = `nslookup $who`;
to :
my $lookup = `/usr/bin/nslookup $who`;
or :
my $lookup = `/bin/nslookup $who`;
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-08-2009 04:20 PM
тАО09-08-2009 04:20 PM
Re: nslookup on list of IPs stored in a file and storing resolved hostname in a file
One more caveat. Depending on the configuration of your DNS servers, non-existent DNS addresses may timeout somewhat slowly. Be patient if no output immediately appears or if output seems to be suspended. You can test with a few "good" addresses and a few "bad" ones. You should also manually run 'nslookup' with one known "good" and one known "bad" adddress to obtain a feel for your environment's behavior.
Regards!
...JRF...