<?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>Kaptain Krayola &#187; ColdFusion</title>
	<atom:link href="http://www.kaptainkrayola.com/category/tools/miscellaneous-code/coldfusion/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kaptainkrayola.com</link>
	<description>You daily dose of internet destruction</description>
	<lastBuildDate>Sun, 15 May 2011 15:34:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>ColdFusion IP to Num and Num to IP for database storage</title>
		<link>http://www.kaptainkrayola.com/coldfusion-ip-to-num-and-num-to-ip-for-database-storage/</link>
		<comments>http://www.kaptainkrayola.com/coldfusion-ip-to-num-and-num-to-ip-for-database-storage/#comments</comments>
		<pubDate>Thu, 14 Jun 2007 18:01:28 +0000</pubDate>
		<dc:creator>The Kaptain</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Miscellaneous Code]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.kaptainkrayola.com/coldfusion-ip-to-num-and-num-to-ip-for-database-storage/</guid>
		<description><![CDATA[Yet another piece of hand and useful code from the Kaptain. There has been a ton of discussion using this example over at Perkiset&#8217;s (AKA The Cache) so The Kaptain took a few minutes to get in on the action. You can find ASP, PHP, and a C based PHP extension at The Cache to [...]]]></description>
			<content:encoded><![CDATA[<p>Yet another piece of hand and useful code from the Kaptain.  There has been a ton of discussion using this example over at <a href="http://www.perkiset.org">Perkiset&#8217;s</a> (AKA The Cache) so The Kaptain took a few minutes to get in on the action.  You can find ASP, PHP, and a C based PHP extension at The Cache to accomplish the same thing but it&#8217;s in ColdFusion here just for fun.</p>
<p>Here you go!</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
</pre></td><td class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfscript</span><span style="color: #0000FF;">&gt;</span></span>
	function ip2num(ip){
		oct1 = listfirst(ip,'.');
		oct2 = listgetat(ip,2,'.');
		oct3 = listgetat(ip,3,'.');
		oct4 = listlast(ip,'.');
&nbsp;
		returnThis = 1 &amp; iif(len(oct1 LT 3),DE(&quot;#repeatstring('0',3-len(oct1))#<span style="color: #0000FF;">#oct1#</span>&quot;),DE(&quot;<span style="color: #0000FF;">#oct1#</span>&quot;)) &amp; iif(len(oct2 LT 3),DE(&quot;#repeatstring('0',3-len(oct2))#<span style="color: #0000FF;">#oct2#</span>&quot;),DE(&quot;<span style="color: #0000FF;">#oct2#</span>&quot;)) &amp; iif(len(oct3 LT 3),DE(&quot;#repeatstring('0',3-len(oct3))#<span style="color: #0000FF;">#oct3#</span>&quot;),DE(&quot;<span style="color: #0000FF;">#oct3#</span>&quot;)) &amp; iif(len(oct4 LT 3),DE(&quot;#repeatstring('0',3-len(oct4))#<span style="color: #0000FF;">#oct4#</span>&quot;),DE(&quot;<span style="color: #0000FF;">#oct4#</span>&quot;)) ;
&nbsp;
		return returnThis;
	}
&nbsp;
&nbsp;
	function num2ip(num){
		num = removechars(num,1,1);
		oct1 = left(num,3);
		oct2 = mid(num,4,3);
		oct3 = mid(num,7,3);
		oct4 = right(num,3);
&nbsp;
		returnThis = &quot;&quot;;
&nbsp;
		for(i = 1; i LTE 4; i = i + 1){
			currOct = evaluate(&quot;oct<span style="color: #0000FF;">#i#</span>&quot;);
			for(z = 1; z LTE 3; z = z + 1){
				if(left(currOct,1) EQ 0){
					currOct = removechars(currOct,1,1);
				}else{
					if(i LT 4){
						returnThis = returnThis &amp; currOct &amp; '.';
					}else{
						returnThis = returnThis &amp; currOct;
					}
				writeOutput(currOct &amp; &quot;<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">br</span><span style="color: #0000FF;">&gt;</span></span>&quot;);
				break;
				}
			}
		}
		return returnThis;
	}
&nbsp;
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfscript</span><span style="color: #0000FF;">&gt;</span></span></pre></td></tr></table></div>

<p>Pretty simple eh?  Here is the usage:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> ipnum <span style="color: #0000FF;">=</span> ip2num<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;64.168.11.1&quot;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> numip <span style="color: #0000FF;">=</span> num2ip<span style="color: #0000FF;">&#40;</span>ipnum<span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
	<span style="color: #0000FF;">#ipnum#</span> - <span style="color: #0000FF;">#numip#</span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span></pre></td></tr></table></div>

<p><strong>The output:<br />
</strong><br />
<br />
Original IP : 64.168.11.1 <br />
ip2num: 1064168011001 <br />
num2ip: 64.168.11.1 </p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kaptainkrayola.com/coldfusion-ip-to-num-and-num-to-ip-for-database-storage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

