Hi,
I need to resolve IP to names in a text file. I was thinking of using some unix commands. Ksh.
Text in file contains a lot of these entries:
..
20 6 <166>%ASA-6-302013: Built inbound TCP connection 12690562 for inside2:10.86.6.20/3678 (10.86.6.20/3678) to inside:10.107.22.12/1947 (10.107.22.12/1947)
20 6 <166>%ASA-6-302013: Built inbound TCP connection 12690562 for inside2:10.100.6.20/3678 (10.86.6.20/3678) to inside:10.107.22.12/1947 (10.107.22.12/1947)
..
I would like to get this result:
..
20 6 <166>%ASA-6-302013: Built inbound TCP connection 12690562 for inside2:10.86.6.20/3678 (10.86.6.20/3678) to inside:10.107.22.12/1947 <SERVERA> (10.107.22.12/1947)
20 6 <166>%ASA-6-302013: Built inbound TCP connection 12690562 for inside2:10.100.6.20/3678 <SERVERC> (10.86.6.20/3678) to inside:10.107.22.12/1947 <SERVERB> (10.107.22.12/1947)
..
So the script should nslookup IP and add the text. But if the IP starts with = 10.86.6 , do not resolve the ip address.
Is that possible ?
Thanks in advanced.
regards
Hasselhaven
please help..... Could it be made with AWK ?
Well, I suppose the tools to use would be nslookup or host (if your OS has that available)
A cheap and nasty host based answer in ksh could be:-
#!/bin/ksh
cat inputlogfile | while read a1 a2 a3 a4 a5 a6 a7 a8 a9 first a11 a12 second a14
do
f="${first%\/*}" # Trim off chars after the slash
f="${f#*:}" # Trim of chars before the colon
s="${second%\/*}" # Trim off chars after the slash
s="${s#*:}" # Trim of chars before the colon
if [ "$f" = "${f%10.86.6.*}" ]
then
host $f | read firstdns rest
else
firstdns=
fi
if [ "$s" = "${s%10.86.6.*}" ]
then
host $s | read seconddns rest
else
seconddns=
fi
echo "$a1 $a2 $a3 $a4 $a5 $a6 $a7 $a8 $a9 $first $firstdns $a11 $a12 $second $seconddns $a14"
done
Probably miles better to do this with an awk but for a small input file then this might suffice.
Robin
Liverpool/Blackburn
UK
1 Like
Here's an awk to try:
awk '
NF==2 && $2!=x{
split($2,H,"/")
if(H[1]!~excl){
while("host "H[1]|getline h)
sub(/\.?\n$/,x,h)
sub($2,$2 RS h)
}
}
1
' FS=: OFS=: RS=" " ORS=" " excl="^10\.86\.6" infile
1 Like