<?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>A Waage Blog &#187; getaddrinfo</title>
	<atom:link href="http://qugstart.com/blog/tag/getaddrinfo/feed/" rel="self" type="application/rss+xml" />
	<link>http://qugstart.com/blog</link>
	<description>Ruby, Rails, Life</description>
	<lastBuildDate>Thu, 10 Nov 2011 00:35:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Resolve a hostname from an IP address in Ruby (Reverse-DNS)</title>
		<link>http://qugstart.com/blog/ruby-and-rails/resolve-a-hostname-from-an-ip-address-in-ruby-reverse-dns/</link>
		<comments>http://qugstart.com/blog/ruby-and-rails/resolve-a-hostname-from-an-ip-address-in-ruby-reverse-dns/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 21:47:43 +0000</pubDate>
		<dc:creator>Andrew Waage</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[Ruby and Rails]]></category>
		<category><![CDATA[getaddrinfo]]></category>
		<category><![CDATA[host]]></category>
		<category><![CDATA[ip]]></category>
		<category><![CDATA[nslookup]]></category>
		<category><![CDATA[resolve]]></category>
		<category><![CDATA[reverse dns]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[socket]]></category>

		<guid isPermaLink="false">http://qugstart.com/blog/?p=10</guid>
		<description><![CDATA[It sounds easy, but I tried a lot of things before finding the solution I used.
I tried using:
`host 66.249.67.49` or
`nslookup 66.249.67.49`

These were fine, but it seems a bit hacky to use the shell. Also, it would require some sort of parsing to get the hostname that I want.
Browsing the web, I found a couple solutions [...]]]></description>
			<content:encoded><![CDATA[<p>It sounds easy, but I tried a lot of things before finding the solution I used.</p>
<p>I tried using:</p>
<pre lang="ruby" class="prettyprint">`host 66.249.67.49` or
`nslookup 66.249.67.49`
</pre>
<p>These were fine, but it seems a bit hacky to use the shell. Also, it would require some sort of parsing to get the hostname that I want.</p>
<p>Browsing the web, I found a couple solutions that almost worked.</p>
<pre lang="ruby" class="prettyprint">s = Socket.getaddrinfo('66.249.67.49',nil)
hostname = s[0][2]
</pre>
<p>This solution worked in IRB, worked in console, but for some reason would not work when I was running my mongrel server and trying to perform the exact same method call from a web-browser. ( I still don&#8217;t know why).</p>
<p>Digging around a bit more, I came up with this simple solution:</p>
<pre lang="ruby" class="prettyprint">host = Resolv.new.getname('66.249.67.49')
</pre>
<p>Is it really that easy?? Give it a shot and let me know your thoughts !!</p>
]]></content:encoded>
			<wfw:commentRss>http://qugstart.com/blog/ruby-and-rails/resolve-a-hostname-from-an-ip-address-in-ruby-reverse-dns/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

