<?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>Altmint Blog &#187; IP Address using php</title>
	<atom:link href="http://blog.altmint.com/tag/ip-address-using-php/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.altmint.com</link>
	<description></description>
	<lastBuildDate>Mon, 24 Oct 2011 09:11:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Get a domain name&#8217;s IP address with PHP</title>
		<link>http://blog.altmint.com/get-a-domain-names-ip-address-with-php</link>
		<comments>http://blog.altmint.com/get-a-domain-names-ip-address-with-php#comments</comments>
		<pubDate>Fri, 09 Apr 2010 12:36:04 +0000</pubDate>
		<dc:creator>Kongoti</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[domain's Ip address]]></category>
		<category><![CDATA[Ip address]]></category>
		<category><![CDATA[IP Address using php]]></category>

		<guid isPermaLink="false">http://blog.altmint.com/?p=107</guid>
		<description><![CDATA[How to get Domain name&#8217;s IP address with PHP ?. It&#8217;s very easy to get the IP address for a domain name using PHP. We have two powerful functions in php to get the IP address of a domain name. Those functions are gethostbyname() gethostbynamel() The first one will returnÂ  IP address corresponding to a <a href="http://blog.altmint.com/get-a-domain-names-ip-address-with-php">Continue Reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<p><strong>How to get Domain name&#8217;s IP address with PHP ?.</strong></p>
<p>It&#8217;s very easy to get the IP address for a domain name using PHP. We have two powerful functions in php to get the IP address of a domain name.</p>
<p>Those functions are</p>
<ol>
<li> gethostbyname()</li>
<li> gethostbynamel()</li>
</ol>
<p>The first one will returnÂ  IP address corresponding to a given Internet host name</p>
<p>The second one will return a list of IP addresses corresponding to a given Internet host name in the form of an array.</p>
<p>We will see some examples using the both functions</p>
<p><strong>Using gethostbyname()</strong></p>
<p>The PHP function gethostbyname() is very simple to use. Simply pass it the domain name you would like to look up and it will either return the IP address for that domain or the unmodified domain back again if it failed. If the domain has more than one IP address associated with it (as with www.cnn.com) then just a single IP address will be passed back.</p>
<p><strong>Example 1</strong></p>
<pre class="brush: php">

&lt;?php

$x = gethostbyname(&#039;www.altmint.com&#039;);
var_dump($x);
// outputs string(13) &quot;96.0.1.231&quot;

?&gt;
</pre>
<p><strong>Example 2</strong></p>
<pre class="brush: php">

&lt;?php

$x = gethostbyname(&#039;www.cnn.com&#039;);
var_dump($x);
// string(14) &quot;157.166.255.19&quot;
// OR string(14) &quot;157.166.255.18&quot;
// OR string(14) &quot;157.166.224.26&quot;
// OR string(14) &quot;157.166.224.25&quot;

?&gt;
</pre>
<p><strong>Example 3</strong></p>
<p>This example is for a non-existant domain and returns the domain itself instead of an IP address:</p>
<pre class="brush: php">

&lt;?php
$x = gethostbyname(&#039;www.blah.foo&#039;);
var_dump($x);
// outputs string(12) &quot;www.blah.foo&quot;

?&gt;
</pre>
<p>If you needed to do something based on the IP address not being found, you could do something like this:</p>
<pre class="brush: php">

&lt;?php
$domain = &#039;www.blah.foo&#039;;
$ip = gethostbyname($domain);
if($domain != $ip) {
// do something
}

?&gt;
</pre>
<p>Note that not being able to find an IP address for the domain does not mean the domain does not exist, or even that a record does not exist for this (sub)domain. The DNS lookup may simply have failed.</p>
<p><strong>Using gethostbynamel()</strong></p>
<p>The PHP gethostbynamel() function returns a list of IP addresses for a domain and Take a look at the following Example.</p>
<p><strong>Example</strong></p>
<pre class="brush: php">

&lt;?php
$hosts = gethostbynamel(&#039;www.example.com&#039;);
print_r($hosts);

//Possible out put will be like this.

Array
(
[0] =&gt; 192.0.34.166
)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.altmint.com/get-a-domain-names-ip-address-with-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

