From owner-freebsd-questions@FreeBSD.ORG Tue Aug 19 06:37:38 2008 Return-Path: Delivered-To: questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 98A08106566B for ; Tue, 19 Aug 2008 06:37:38 +0000 (UTC) (envelope-from ws@au.dyndns.ws) Received: from ipmail05.adl2.internode.on.net (ipmail05.adl2.internode.on.net [203.16.214.145]) by mx1.freebsd.org (Postfix) with ESMTP id 32D3F8FC25 for ; Tue, 19 Aug 2008 06:37:37 +0000 (UTC) (envelope-from ws@au.dyndns.ws) Received: from ppp103-111.static.internode.on.net (HELO [192.168.1.157]) ([150.101.103.111]) by ipmail05.adl2.internode.on.net with ESMTP; 19 Aug 2008 15:50:27 +0930 From: Wayne Sierke To: Paul Schmehl In-Reply-To: References: <52CC1A3B-5826-4E06-9325-0E43E5A58E78@goldmark.org> Content-Type: text/plain; charset=UTF-8 Date: Tue, 19 Aug 2008 15:50:25 +0930 Message-Id: <1219126825.49053.51.camel@predator-ii.buffyverse> Mime-Version: 1.0 X-Mailer: Evolution 2.22.2 FreeBSD GNOME Team Port Content-Transfer-Encoding: 8bit Cc: FreeBSD Questions Subject: Re: How to use dig with an ip list X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Aug 2008 06:37:38 -0000 On Mon, 2008-08-18 at 22:52 -0500, Paul Schmehl wrote: > --On August 18, 2008 10:13:54 PM -0500 Jeffrey Goldberg > 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!)