<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Storing IP Addresses in MYSQL</title>
	<atom:link href="http://www.ebrueggeman.com/blog/mysql/storing-ip-addresses-in-mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ebrueggeman.com/blog/mysql/storing-ip-addresses-in-mysql/</link>
	<description>Tips and Tricks for Web Developers</description>
	<pubDate>Wed, 03 Dec 2008 23:03:39 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Cypher</title>
		<link>http://www.ebrueggeman.com/blog/mysql/storing-ip-addresses-in-mysql/#comment-27</link>
		<dc:creator>Cypher</dc:creator>
		<pubDate>Tue, 02 Sep 2008 13:34:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.ebrueggeman.com/blog/php/storing-ip-addresses-in-mysql/#comment-27</guid>
		<description>Remember that you can convert those values in mysql as well:
INET_ATON() - Return the numeric value of an IP address
INET_NTOA() - Return the IP address from a numeric value

E.g.
SELECT INET_ATON("255.255.255.0");
will return "4294967040" and
SELECT INET_NTOA(4294967040);
will return "255.255.255.0".</description>
		<content:encoded><![CDATA[<p>Remember that you can convert those values in mysql as well:<br />
INET_ATON() - Return the numeric value of an IP address<br />
INET_NTOA() - Return the IP address from a numeric value</p>
<p>E.g.<br />
SELECT INET_ATON(&#8221;255.255.255.0&#8243;);<br />
will return &#8220;4294967040&#8243; and<br />
SELECT INET_NTOA(4294967040);<br />
will return &#8220;255.255.255.0&#8243;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elliott Brueggeman</title>
		<link>http://www.ebrueggeman.com/blog/mysql/storing-ip-addresses-in-mysql/#comment-4</link>
		<dc:creator>Elliott Brueggeman</dc:creator>
		<pubDate>Thu, 29 Nov 2007 21:48:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.ebrueggeman.com/blog/php/storing-ip-addresses-in-mysql/#comment-4</guid>
		<description>Not a bug - actually if you are searching for a range of IP addresses, you need to convert the range using ip2long() and then search for that in MySQL.

&lt;strong&gt;Example:&lt;/strong&gt;

You want to find an IP address in the range 192.168.0.0 to 192.168.255.255.

So convert those bounds to long format using php:

$bound1=ip2long('192.168.0.0); //this is -1062731776
$bound2=ip2long('192.168.255.255'); //this is -1062666241

Then do a MySQL query:

$sql="SELECT * FROM ip_table where ip BETWEEN $bound1 AND $bound2";

Remember that the first argument of BETWEEN must be the smaller number.</description>
		<content:encoded><![CDATA[<p>Not a bug - actually if you are searching for a range of IP addresses, you need to convert the range using ip2long() and then search for that in MySQL.</p>
<p><strong>Example:</strong></p>
<p>You want to find an IP address in the range 192.168.0.0 to 192.168.255.255.</p>
<p>So convert those bounds to long format using php:</p>
<p>$bound1=ip2long(&#8217;192.168.0.0); //this is -1062731776<br />
$bound2=ip2long(&#8217;192.168.255.255&#8242;); //this is -1062666241</p>
<p>Then do a MySQL query:</p>
<p>$sql=&#8221;SELECT * FROM ip_table where ip BETWEEN $bound1 AND $bound2&#8243;;</p>
<p>Remember that the first argument of BETWEEN must be the smaller number.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jbagley</title>
		<link>http://www.ebrueggeman.com/blog/mysql/storing-ip-addresses-in-mysql/#comment-3</link>
		<dc:creator>jbagley</dc:creator>
		<pubDate>Thu, 29 Nov 2007 20:14:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.ebrueggeman.com/blog/php/storing-ip-addresses-in-mysql/#comment-3</guid>
		<description>Nice.  But, I need to be able to write a query that returns all ip addresses like 192.168.  The function doesn't behave well with incomplete ip addresses.

192.168 becomes -1073741656
-1073741656 returns to 192.0.0.168

Maybe a bug?</description>
		<content:encoded><![CDATA[<p>Nice.  But, I need to be able to write a query that returns all ip addresses like 192.168.  The function doesn&#8217;t behave well with incomplete ip addresses.</p>
<p>192.168 becomes -1073741656<br />
-1073741656 returns to 192.0.0.168</p>
<p>Maybe a bug?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sroberts</title>
		<link>http://www.ebrueggeman.com/blog/mysql/storing-ip-addresses-in-mysql/#comment-2</link>
		<dc:creator>sroberts</dc:creator>
		<pubDate>Thu, 22 Nov 2007 18:12:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.ebrueggeman.com/blog/php/storing-ip-addresses-in-mysql/#comment-2</guid>
		<description>This is interesting - I have IP Addresses stored as a varchar. I didn't even realize you could store them a different way. Well done!</description>
		<content:encoded><![CDATA[<p>This is interesting - I have IP Addresses stored as a varchar. I didn&#8217;t even realize you could store them a different way. Well done!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
