We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 38,951 times

Contents

Related Categories

Extracting the Country from the IP Address:- How To? - The Full Code

amitgupta

The Full Code

So, after doing bits of code, here's the full code for our application:-

<% @language="VBScript" %>
<%
Private Function ipAd2ipNum(ipA)
strO = ipA
pos1 = InStr(strO, ".")
intA = CInt(Left(strO, (pos1-1)))
strO2 = Mid(strO, pos1+1, len(strO))
pos2 = InStr(strO2, ".")
intB = CInt(Left(strO2, (pos2-1)))
strO3 = Mid(strO2, pos2+1, len(strO2))
pos3 = InStr(strO3, ".")
intC = CInt(Left(strO3, (pos3-1)))
intD = CInt(Mid(strO3, pos3+1, len(strO3)))

intConvert = (intA*(256*256*256)) + (intB*(256*256)) + (intC*256) + intD
ipAd2ipNum = Trim(intConvert)
End Function

 

strIP = Request.ServerVariables("HTTP_REMOTE_ADDR")
strIPN = ipAd2ipNum(strIP)

 

strConString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="
strConString = strConString & Server.MapPath("ip2country.mdb")

Set objCon = Server.CreateObject("ADODB.Connection")
objCon.Open strConString

strSQL = "select co_name from ip2c where ip_from<=" & strIPN
strSQL = strSQL & "and ip_to>=" & strIPN

Set objRs = Server.CreateObject("ADODB.Recordset")
objRs.Open strSQL,objCon
If NOT(objRs.EOF) OR NOT(objRs.BOF) Then
strCountry = objRs.Fields("co_name")
%>
Your IP Address is :- <%=strIP%><br>
Your Country is :- <%=strCountry%>
<%
Else
%>
Your IP Address is :- <%=strIP%><br>
Your Country is :- <b>unlisted</b>
<%
End If

objRs.Close
objCon.Close
Set objRs = nothing
Set objCon = nothing
Set strSQL = nothing
%>



This wraps up our tutorial Extracting the Country from the IP Address:- How To?

But a few final words....

Comments