I create a table in Db
ip2country
Name Null? Type
----------------------------------------- -------- ------------------------
----
SOURCE VARCHAR2(255)
CREATED DATE
COUNTRY VARCHAR2(255)
IP_FROM VARCHAR2(255)
IP_TO VARCHAR2(255)
IP_FROM_NUM NUMBER
IP_TO_NUM NUMBER
IP_RANGE NUMBER
and populate from
IP Registration:
1.
****************************************************************************
*****
apnic - Asia Pacific Network Information Center
File - free
URI -
http://www.apnic.org/
Path - ftp://ftp.apnic.net/pub/apnic/stats/apnic/
2.
****************************************************************************
*****
lacnic - Latin American and Caribbean Internet
Addresses Registry
URI -
http://lacnic.net
File - free
Path - ftp://ftp.lacnic.net/pub/stats/lacnic/
3.
****************************************************************************
*****
arin - American Registry for Internet Numbers
File - free
URI -
http://www.arin.net
Path - ftp://ftp.arin.net/pub/stats/arin/
4.
****************************************************************************
*****
ripe - Regional Internet Registries (RIR) in
Europe
File - free
URI -
http://www.ripe.net
Path - ftp://ftp.ripe.net/ripe/stats/
****************************************************************************
*********
you need convert ip string to long
Public Function Convert_String_Ip_To_Long(ByVal In_Ip As String) As Long
Dim int_Index As Integer
Dim lngResults As Long
Dim IpArr As String()
IpArr = In_Ip.Split(".".ToCharArray)
For int_Index = 0 To 3
If Not int_Index = 3 Then
' Convert the number To a value range that can be parsed from the
others
IpArr(int_Index) = (CLng(IpArr(int_Index)) * (256 ^ (3 -
int_Index))).ToString
End If
' Add the number To the results
lngResults = lngResults + CLng(IpArr(int_Index))
Next
Return lngResults
End Function
Public Function Convert_Long_Ip_To_String(ByVal In_Ip As Long) As String
Dim _Ip As IPAddress = New IPAddress(In_Ip)
Dim Result As String = ""
Dim Arr As String()
Arr = (_Ip.ToString).Split(".".ToCharArray)
For i As Integer = 3 To 0 Step -1
If i = 0 Then
Result = Result & Arr(i)
Else
Result = Result & Arr(i) & "."
End If
Next
Return Result
End Function
it will be easy to search in DB
example:
If s.StartsWith("ripencc|") Then
line = s.Split("|".ToCharArray)
If line(2) = "ipv4" And line(1) <> "*" Then
If IsNumeric(line(4)) Then
range = CLng(line(4))
ipFrom = Convert_String_Ip_To_Long(line(3))
ipFromStr = line(3)
ipTo = ipFrom + range
ipToStr = Convert_Long_Ip_To_String(ipTo)
sql &= " Insert Into IP2COUNTRY (SOURCE,CREATED,
COUNTRY,IP_FROM_NUM,IP_TO_NUM,IP_FROM,IP_TO,IP_RANGE )"
sql &= " VALUES ('RIPENCC',SYSDATE"
sql &= "," & _quote(line(1))
sql &= "," & ipFrom
sql &= "," & ipTo
sql &= "," & _quote(ipFromStr)
sql &= "," & _quote(ipToStr)
sql &= "," & range
sql &= " )"
Execute_DML(sql, Cnn)
End If
End If