Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace an IP-Address by DNS name

Status
Not open for further replies.

ziwo

Technical User
Apr 1, 2004
1
CH
Hi,

I have to parse a huge html file and should replace every occurrence of an IP address by their DNS name. So, during the run I should be able to do a nslookup (or similar).

I can imagine also a two step version:
extract the IP adresses first and create a lookup table
<IP> <DNS name>
<IP> <DNS name>
...
and use this table for replacing the IP addresses in the html file (to prevent the nslookup during the script run).

I'm not sure if awk is my solution.

Any help or pointer is verry welcome.

- ziwo

 
Something like this might work. You would need to pass appropriate flags to nslookup and extract the DNS name out of the dns array.

{
match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/)
while (RSTART) {
ip = substr($0,RSTART,RLENGTH)
"nslookup " ip | getline dns
sub(ip,dns)
match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/)
}
}

CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top