Date: Tue, 19 Aug 2008 15:50:25 +0930 From: Wayne Sierke <ws@au.dyndns.ws> To: Paul Schmehl <pauls@utdallas.edu> Cc: FreeBSD Questions <questions@freebsd.org> Subject: Re: How to use dig with an ip list Message-ID: <1219126825.49053.51.camel@predator-ii.buffyverse> In-Reply-To: <C2F700D5D04999507E393C99@Macintosh.local> References: <F00086DB609A849EAB40A058@Macintosh.local> <52CC1A3B-5826-4E06-9325-0E43E5A58E78@goldmark.org> <C2F700D5D04999507E393C99@Macintosh.local>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 2008-08-18 at 22:52 -0500, Paul Schmehl wrote: > --On August 18, 2008 10:13:54 PM -0500 Jeffrey Goldberg > <jeffrey@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!)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1219126825.49053.51.camel>