<cffunction name="getIPInfo" output="yes" returntype="any">
<cfargument name="ip" type="any" required="Yes">
<cfset var cfhttp = "">
<cfset var rez = "">
<cfset var theXML = "">
<cfhttp url="http://www.whois-api.com/?#IP#" method="GET" useragent="Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14"/>
<cfif IsXML(cfhttp.FileContent)>
<cfset theXML = XMLParse(cfhttp.FileContent)>
<cfset rez = StructNew()>
<cfif not StructKeyExists(theXML, "ipdata")>
<cfset rez.isError = 1>
<cfset rez.message = cfhttp.FileContent>
<cfelse>
<cfset rez.isError = 0>
<cfif StructKeyExists(theXML.ipdata, "ip")>
<cfset rez.ip = theXML.ipdata.ip.XmlText>
</cfif>
<cfif StructKeyExists(theXML.ipdata, "code")>
<cfset rez.code = theXML.ipdata.code.XmlText>
</cfif>
<cfif StructKeyExists(theXML.ipdata, "country")>
<cfset rez.country = theXML.ipdata.country.XmlText>
</cfif>
<cfif StructKeyExists(theXML.ipdata, "city")>
<cfset rez.city = theXML.ipdata.city.XmlText>
</cfif>
<cfif StructKeyExists(theXML.ipdata, "areacode")>
<cfset rez.areacode = theXML.ipdata.areacode.XmlText>
</cfif>
<cfif StructKeyExists(theXML.ipdata, "area")>
<cfset rez.area = theXML.ipdata.area.XmlText>
</cfif>
<cfif StructKeyExists(theXML.ipdata, "isp")>
<cfset rez.isp = theXML.ipdata.isp.XmlText>
</cfif>
<cfif StructKeyExists(theXML.ipdata, "organization")>
<cfset rez.organization = theXML.ipdata.organization.XmlText>
</cfif>
<cfif StructKeyExists(theXML.ipdata, "location")>
<cfset rez.latitude = theXML.ipdata.location.mm.latitude.XmlText>
<cfset rez.longitude = theXML.ipdata.location.mm.longitude.XmlText>
</cfif>
</cfif>
<cfelse>
<cfset rez = cfhttp.FileContent>
</cfif>
<cfreturn rez>
</cffunction>
Posted At : Nov 28, 2008 13:24 PM
| Posted By : Ed Tabara
Related Categories: ColdFusion
Related Categories: ColdFusion
I found a site that seem to return GEO IP information in a XML format without any registration, fees, etc. So, i made this quick function that being provided with an IP address will return all provided information.
| 52156 Views
| 60% / 0% Popularity
Comments
That's cool mate. Thanks for sharing
Posted By Marcos Placona | Nov 28, 2008 16:04 PM