#!/usr/bin/perl -p # # $Id: resolveips,v 1.2 2000/07/18 03:17:24 cos Exp cos $ # # reads text on stdin, and spits it to stdout with anything that looks # like a dotted-quad IP address resolved to a hostname (or marked unresolved) use Socket 'AF_INET'; #$debug=1; warn "----------\n$_" if $debug; foreach $ipadr (/(\d+\.\d+\.\d+\.\d+)(?!\d)/g) { $addr = pack("C4", split(/\./, $ipadr)); unless ($hname = $hname{$addr}) { $hname = gethostbyaddr $addr, AF_INET; $hname = "[$ipadr]" unless $hname; $hname{$addr} = $hname; warn "*** resolved $ipadr -> $hname\n" if $debug; } s/\Q$ipadr/$hname/ if $hname; warn "\t$ipadr:\t$hname\n" if $debug; }