<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>cyberpir8.net &#187; command line</title>
	<atom:link href="http://www.cyberpir8.net/tag/command-line/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cyberpir8.net</link>
	<description>Here lies da booty</description>
	<lastBuildDate>Mon, 17 Oct 2011 04:38:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Quick nslookup bash script</title>
		<link>http://www.cyberpir8.net/2009/10/06/quick-nslookup-bash-script/</link>
		<comments>http://www.cyberpir8.net/2009/10/06/quick-nslookup-bash-script/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 20:55:01 +0000</pubDate>
		<dc:creator>Jed</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://www.cyberpir8.net/?p=192</guid>
		<description><![CDATA[I recently had to determine if a large set of URLs resolved to the same set of IP addresses. Knowing a little about a few different scripting languages/technologies let me know that this was definitely possible, so I just had to figure out which one I wanted to use for the most efficient results. I [...]]]></description>
			<content:encoded><![CDATA[<img style='float: left; margin-right: 10px; border: none;' src='http://www.gravatar.com/avatar.php?gravatar_id=fa2982ef8b1f91a02ab1c6a85f9b7a2a&amp;default=http://www.gravatar.com/avatar.php' alt='No Gravatar' width=40 height=40/><p>I recently had to determine if a large set of URLs resolved to the same set of IP addresses.  Knowing a little about a few different scripting languages/technologies let me know that this was definitely possible, so I just had to figure out which one I wanted to use for the most efficient results.  I decided to just go with Bash shell scripting (since I&#8217;ve recently gotten a little used to it).</p>
<p>Say I have a file called urls.txt (newline delimited).  This file started with more than just the hostname (e.g., <a href="http://www.example.com/foo/bar.aspx" class="autohyperlink" title="http://www.example.com/foo/bar.aspx" target="_blank">www.example.com/foo/bar.aspx</a>).  I had to pare those down so I opened the list in vim and did a little replacement.  I could have done the same thing with sed but I&#8217;m most familiar with doing this in vim.  In vim, open the file and type:</p>
<p><code>:%s#/.*##g</code></p>
<p>Ok, ready for some nslookup action in a Cygwin Bash loop.  Note that this does not output what I&#8217;d like to do, which is the format of &#8220;url,ip&#8221; and output to a .csv file.  It&#8217;s also important to note that the loop will take the input line-by-line, so the output file will have all the results in the right order.  I could do this in perl very quickly and get the results I&#8217;m looking for, but it takes that much more time to write the script.  Anyway, here it is:</p>
<p><code>$ for i in `cat urls.txt`; do nslookup $i 198.6.1.4 2&gt;/dev/null | grep Address | tail -n 1 | cut -d " " -f 3; done &gt; ips.txt</code></p>
<p>The &#8220;$&#8221; is the prompt, so don&#8217;t write that.  For all values (i.e. lines) in urls.txt, do an nslookup of the url and specify the <a href="http://uu.net" class="autohyperlink" title="http://uu.net" target="_blank">uu.net</a> DNS server to avoid any problems with local resolution (I was having trouble, so had to go outside my corporate DNS server).  Redirect all nslookup STDERR messages to /dev/null (there&#8217;s a header).  Only show me the lines with &#8220;Address&#8221; and only give me the last of those lines (head &amp; tail working together).  Then strip the &#8220;Address: &#8221; from the remaining line to give me the IP address by itself.  And when you&#8217;re done with all that work, redirect to ips.txt instead of STDOUT.</p>
<p>Now I open an Excel or Calc spreadsheet and drop the values from urls.txt right next to ips.txt and I&#8217;m cooking with gas.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cyberpir8.net/2009/10/06/quick-nslookup-bash-script/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

