in reply to Retrieving all hostnames for an IP address...
Any questions on the above code, please feel free to ask. Thanks again, RMaxwelluse strict; # Performs strict error checking throughout th +e program use POSIX; # Loads the POSIX module for standardized C fu +nctions use NET::Ping; # Loads the Net::Ping module for ICMP/UDP/TCP +Pinging use Socket; # Loads the Socket module for Socket level com +munications . . . sub Retest_Name { &writelog("Beginning Name to IP Address Retests"); foreach (@Nlist) { my $hst = $_; my $res; if ($res = gethostbyname($hst)) { my $ip = inet_ntoa($res); push @GNaddr, "$hst|DNS - $ip\n"; } else { push @BNaddr, "$hst|Name doesn't resolve to an IP $!\n"; } } &writelog("Completed Name to IP Address Retests"); } sub Retest_IP { &writelog("Beginning IP to Name Address Retests"); open CF, "<", $cfile or &writelog("Unable to open $cfile for readi +ng!!!") and die; my @CFlist = (); # The below while statement reads in and processes the data in the + ipNoLookup.conf # and places the data into an array. while (<CF>) { my $in = chomp $_; my ($ip, $junk) = split(/\t/, $in); my ($ip1, $ip2, $ip3, $ip4) = split(/./, $ip); my ($sip1, $sip2); undef $ip; if ($ip4 =~ /([0-9]+\-[0-9]+)/) { ($sip1, $sip2) = split(/\-/, $ip4); while ($sip1 != $sip2) { $ip = join (".", $ip1, $ip2, $ip3, $sip1); push @CFlist, $ip; undef $ip; $sip1++; } $ip = join (".", $ip1, $ip2, $ip3, $sip2); push @CFlist, $ip; undef $ip; } else { $ip = join (".", $ip1, $ip2, $ip3, $ip4); push @CFlist, $ip; undef $ip; } } # The foreach routine compares the IPs received from the trace fil +es against the # array generated from the ipNoLookup.conf in use on the system, a +nd eliminates # any matches. my $IPidx = 0; foreach (@IPlist) { my $hst = chomp $_; foreach (@CFlist) { my $chst = chomp $_; if ($hst eq $chst) { delete $IPlist[$IPidx]; } } $IPidx++; } # The foreach routine reads each line from the @IPlist array and r +eprocesses it foreach (@IPlist) { my $hst = $_; my $iaddr = inet_aton($hst); ($name,$aliases,$addrtype,$length,@addrs) = gethostbyaddr($iad +dr, AF_INET); if (length ($name) == 0 || $name =~ /[various|hostnames|totest +from]\.internal\.domain\.name/) { my $p = Net::Ping->new(); if ($p->ping($hst)) { $ires = "ICMP Responded"; } else { $ires = "No ICMP Response"; } $p->close(); undef $p; $p = Net::Ping->new("tcp", 2); $p->{port_num} = getservbyname("http", "tcp"); $p->service_check(1); my $res = $p->ping($hst); if ($res == 1) { $hres = "HTTP Responded"; } else { $hres = "No HTTP Response"; } $p->close(); undef $p; undef $res; $p = Net::Ping->new("tcp", 2); $p->{port_num} = getservbyname("telnet", "tcp"); $p->service_check(1); $res = $p->ping($hst); if ($res == 1) { $tres = "Telnet Responded"; } else { $tres = "No Telnet Response"; } $p->close(); undef $p; undef $res; push @BIaddr, "$hst|$ires, $hres, $tres\n"; undef $hst; undef $ires; undef $hres; undef $tres; } else { $name = $name . " " . $aliases; push @GIaddr, "$hst|DNS - $name\n"; undef $hst; undef $name; } } &writelog("Completed IP to Name Address Retests"); }
|
|---|