how to get the country ?

A

Alex K

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
 
J

John Saunders

Alex K said:
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:

Is it possible for an IP to be registered to an entity in one country, but
used by that entity in another country? For example, are there not ISPs and
other communications entities with operations in several countries? Might
they not be allocated a set of IP addresses, recorded by the country of
their headquarters, and then use some of those IP addresses in their
country, and some in other countries in which they provide services?
 
A

Alex K

Yes but the is no database records about that.

John Saunders said:
----------------------------------------- -------- ----------------------
--

Is it possible for an IP to be registered to an entity in one country, but
used by that entity in another country? For example, are there not ISPs and
other communications entities with operations in several countries? Might
they not be allocated a set of IP addresses, recorded by the country of
their headquarters, and then use some of those IP addresses in their
country, and some in other countries in which they provide services?
 
J

John Saunders

Alex K said:
Yes but the is no database records about that.

So, if this isn't recorded anywhere, it's a waste of time to use the IP
address to get the country, right?

I mean, if an ISP is allocated a number of Class C addresses, and is
headquartered in one country, what's to stop them from using one of those
Class C's in a second country? Nothing, as far as I know.

Another example: assume that you are a server program, receiving TCP/IP
connections, acting on the request, and then responding and (often) closing
the connection. Your first request of the day is from 207.46.134.222.Five
minutes later, you get a request from 207.46.134.221. Can you assume that
these two IP addresses are from machines which are close to each other? What
if you get another request from 207.46.134.222. Can you assume that it is
from the same machine which sent you the first request? No! It may be an IP
address handed out by a NAT box or some other piece of Network-layer
hardware or software. The two machines may not even be in the same country!

IP addresses are just supposed to be something for the Network Layer to use
to route packets. They're not supposed to be used by anyone else for
anything else.
 
A

Alex K

Ok we have contract that we pay only for us traffic

client give us 10-15 millions view a day. Base on example from my previous
email

Stats showing that only 99.5% from US

So client is cheating 0.5% or users locating on different hosting you never
get 100% correct data

We try NETIQ (webtrends.com) (they ask $2500 a month) stats that they give
us are the same so I can say that method 99.5% accurate and it is free.

if you give me a big picture what are you trying to do maybe I will give you
example from my experience



Alex

(e-mail address removed)
 
L

Lloyd Dupont

I just wanted a rough and easy estimated of the country of the user.
I don't feel like decyphering APNIC data just for the sake of it, but
thanks Alex for this accurate info :)

Anyway I already ask the user for its favourite language, so I could just
use this information I guess, it would be good enough for my prupose ..

thanks !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top