Iterative operation

grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' then how do i iterate the file names??

You don't really need iteration, just add more file names to the grep command line.

ohh well that works for me

Exactly. The grep output changes so that each match is prefixed with the file name. There are options to turn that off if you don't need it.

if i then use the code to look up DNS then should i do it with nslookup host or dig?...i know dig is more useful which i read ....but if you could state the use of IFS then it will be great.

Recent versions of host can perform a reverse DNS lookup directly on the IP address. If you have an older version, or wish to use dig or some other tool, you have to convert the IP address into the format used internally for reverse DNS lookups. Here is an example.

OLDIFS=$IFS
IFS=.
set -- $ip
IFS=$OLDIFS
echo IP=$ip, hostname=`dig +short ptr $4.$3.$2.$1.in-addr.arpa.`

so how does this work :

grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' File.tx | while read ip; do nslookup

The error message doesn't make sense. Can you copy+paste the exact error message?

The -o option doesn't really achieve anything if the IP addresses are alone on a line. If they're not, your regex is wrong (probably drop the ^ and $ then).

grep whatever |
while read ip; do
  OLDIFS=$IFS
  IFS=.
  set -- $ip
  IFS=$OLDIFS
  echo IP=$ip, hostname=`dig +short ptr $4.$3.$2.$1.in-addr.arpa.`
done

ok how does this look like then

grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' files |
while read ip; do OLDIFS=$IFS; IFS=.; set -- $ip; IFS=$OLDIFS;
echo IP=$ip, hostname=`dig +short ptr $4.$3.$2.$1.in-addr.arpa.`;

You'd replace the "whatever" with the command you use to extract the IP addresses.

yeah i did .....i think u missed it

You need to split it over multiple lines, or add semicolons between the commands. Also, the done seems to be missing.

grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' Filename.txt |
while read ip; do OLDIFS=$IFS; IFS=.; set -- $ip; IFS=$OLDIFS;
  echo IP=$ip, hostname=`dig +short ptr $4.$3.$2.$1.in-addr.arpa.`; done

i am removing this thread

dig is more scripting friendly (with the +short option you get just what you asked for, no "human-readable" chaff to remove), but if you prefer nslookup or host, adapt as needed.

hey

i tried exactly the command you gave me and still doesnt work....it just gives me the next command prompt.
I tried with the ns lookup but still doesnt help....

In the meantime, can you enlighten us regarding the similarities between this thread and these:

ds ss slsl sos

What can I say other than works for me.

vnix$ cat >/tmp/ip
If I were a rich man I'd pwn 81.17.242.186 but I'm not so I don't.
^D
vnix$ grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' /tmp/ip |
> while read ip; do OLDIFS=$IFS; IFS=.; set -- $ip; IFS=$OLDIFS;
>   echo IP=$ip, hostname=`dig +short ptr $4.$3.$2.$1.in-addr.arpa.`; done
IP=81.17.242.186, hostname=www.unix.com.

Do u think that coz i am using ubuntu it can be a problem?

i got the mistake i was making...i forgot to leave the space in one of the arguments