Forum Topics : Support / SQL Server 2000 Complete ASP.NET Solution w/VB.NET Code Behind
Procedure
1) Edit IPCountry.csv (with excel)
- Delete the Column with the 3 letter country abbreviations unless you need it! I didn't need it
2) Edit IPCountry.csv (with excel)
- In the very first row do an insert and put:
ipFROM
ipTO
countrySHORT
countryLONG
(Doing this makes it easier to import into SQL Server 2000)
3) Import the IPCountry.csv with the new modifications into your SQL Server Database into a table called "tblIPCountry"
4) Once you imported it you should have a design view of:
[tblIPCountry]
ipFROM (example 1003230032)
ipTO (example 1123892933)
countrySHORT (example US)
countryLONG (example United States)
5) Use the following SQL Query from ASP.NET or VB.NET or whatever -
SELECT countrySHORT, countryLONG
FROM tblIPCountry
WHERE '" & ConvertToLong(IPAddress) & "'
BETWEEN ipFROM AND ipTO
6) Here is the function that will convert an IP Address from it's IP format to Long.
------------------------------------------------------------
Private Function ConvertToLong(ByVal IPAddress As Object) As Object
Dim x As Integer
Dim Pos As Integer
Dim PrevPos As Integer
Dim Num As Integer
If UBound(Split(IPAddress, ".")) = 3 Then
' On Error Resume Next
For x = 1 To 4
Pos = InStr(PrevPos + 1, IPAddress, ".", 1)
If x = 4 Then Pos = Len(IPAddress) + 1
Num = Int(Mid(IPAddress, PrevPos + 1, Pos - PrevPos - 1))
If Num > 255 Then
ConvertToLong = "0"
Exit Function
End If
PrevPos = Pos
ConvertToLong = ((Num Mod 256) * (256 ^ (4 - x))) + ConvertToLong
Next
End If
End Function
-------------------------------------------------------------
Summary:
You have the tools now to convert a users IP Address to Long first. Then submit that value to the database and it will return the Country the IP is from.
Enjoy
HoltMelder
1) Edit IPCountry.csv (with excel)
- Delete the Column with the 3 letter country abbreviations unless you need it! I didn't need it
2) Edit IPCountry.csv (with excel)
- In the very first row do an insert and put:
ipFROM
ipTO
countrySHORT
countryLONG
(Doing this makes it easier to import into SQL Server 2000)
3) Import the IPCountry.csv with the new modifications into your SQL Server Database into a table called "tblIPCountry"
4) Once you imported it you should have a design view of:
[tblIPCountry]
ipFROM (example 1003230032)
ipTO (example 1123892933)
countrySHORT (example US)
countryLONG (example United States)
5) Use the following SQL Query from ASP.NET or VB.NET or whatever -
SELECT countrySHORT, countryLONG
FROM tblIPCountry
WHERE '" & ConvertToLong(IPAddress) & "'
BETWEEN ipFROM AND ipTO
6) Here is the function that will convert an IP Address from it's IP format to Long.
------------------------------------------------------------
Private Function ConvertToLong(ByVal IPAddress As Object) As Object
Dim x As Integer
Dim Pos As Integer
Dim PrevPos As Integer
Dim Num As Integer
If UBound(Split(IPAddress, ".")) = 3 Then
' On Error Resume Next
For x = 1 To 4
Pos = InStr(PrevPos + 1, IPAddress, ".", 1)
If x = 4 Then Pos = Len(IPAddress) + 1
Num = Int(Mid(IPAddress, PrevPos + 1, Pos - PrevPos - 1))
If Num > 255 Then
ConvertToLong = "0"
Exit Function
End If
PrevPos = Pos
ConvertToLong = ((Num Mod 256) * (256 ^ (4 - x))) + ConvertToLong
Next
End If
End Function
-------------------------------------------------------------
Summary:
You have the tools now to convert a users IP Address to Long first. Then submit that value to the database and it will return the Country the IP is from.
Enjoy
HoltMelder
