How to use dig with an ip list
Wayne Sierke
ws at au.dyndns.ws
Tue Aug 19 06:37:38 UTC 2008
On Mon, 2008-08-18 at 22:52 -0500, Paul Schmehl wrote:
> --On August 18, 2008 10:13:54 PM -0500 Jeffrey Goldberg
> <jeffrey at goldmark.org> wrote:
>
> > On Aug 18, 2008, at 9:03 PM, Paul Schmehl wrote:
> >
> >> I know I'm missing the obvious. I want to use an IP list to
> >> generate an ip+hostname list. IOW, I want to go from this:
> >>
> >> x.x.x.x
> >> y.y.y.y
> >>
> >> to this;
> >>
> >> x.x.x.x foo.domain.tld
> >> y.y..y.y bar.domain.tld
> >>
> >> What's the best/easiest way to do this?
> >
> > Easiest:
> >
> > $ for i in `cat ip-list`; do
> > > echo -n "$i "
> > > dig +short -x $i
> > > done
> >
>
> Don't know why I didn't think of that.
>
> I ended up using this:
> for ip in `cat public_linux_ips`; do echo ${ip} `dig +short -x ${ip}`;
> done > public_linux_ips_resolved
>
> Which gave me the output I wanted. Thanks for the pointer.
>
Easiestest?
# host www.freebsd.org
www.freebsd.org has address 69.147.83.33
www.freebsd.org has IPv6 address 2001:4f8:fff6::21
www.freebsd.org mail is handled by 0 .
# host ftp.freebsd.org
ftp.freebsd.org has address 62.243.72.50
ftp.freebsd.org has address 204.152.184.73
ftp.freebsd.org has IPv6 address 2001:6c8:6:4::7
ftp.freebsd.org has IPv6 address 2001:4f8:0:2::e
# cat > freebsd.ips
69.147.83.33
62.243.72.50
204.152.184.73
# host 69.147.83.33
33.83.147.69.in-addr.arpa domain name pointer www.freebsd.org.
# awk '{ip=$1; "host "ip | getline; print ip,$NF }' freebsd.ips
69.147.83.33 www.freebsd.org.
62.243.72.50 ftp.beastie.tdk.net.
204.152.184.73 freebsd.isc.org.
s/host/dig/ to taste
The middle command - "host "ip | getline; - executes the 'cmd' part on
the left side of the pipe, getline parses the output, hence $NF now
gives the last field in the output from "host".
Wayne
(You don't know the power of the awk side!)
More information about the freebsd-questions
mailing list