Web Hosting Info

Search:

featured partner

The IP to Country Database

  Forum Topics : Development / Coldfusion ip address to ip number
Submitted by thiazzz on Wed, 01/07/2004 - 10:07.
Just to share this code i've written in Coldfusion: #ipaddress# #ipnumber# SELECT * FROM country_ip WHERE #ipnumber# >= ip_from AND #ipnumber# <= ip_to
Comment viewing options:
Select your preferred way to display the comments and click 'Save settings' to submit your changes.
Mmm that did not come out nicely:
Posted by thiazzz on Wed, 01/07/2004 - 10:11.
<cfset ipaddress="#cgi.remote_addr#">
<cfset a = ListFirst(ipaddress,".")>
<cfset a_rest = ListRest(ipaddress, ".")>
<cfset b = ListFirst(a_rest, ".")>
<cfset b_rest = ListRest(a_rest, ".")>
<cfset c = ListFirst(b_rest, ".")>
<cfset c_rest = ListRest(b_rest,".")>
<cfset d = ListFirst(c_rest, ".")>
<cfset ipnumber = 16777216*a + 65536*b + 256*c + d>

<cfoutput>
#ipaddress#
#ipnumber#
</cfoutput>
 
Better Solution
Posted by kkrems on Mon, 01/26/2004 - 18:54.
cfset ipaddress="#cgi.remote_addr#"
cfset IPArray = listToArray(IPAddress,".")
cfset IPNumber= (IPArray[1] * (256)^3) + (IPArray[2] * (256)^2) + (IPArray[3] * 256) + IPArray[4]

You would probably want to place some conditional logic as well.

Kurt