By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,583 Members | 1,042 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,583 IT Pros & Developers. It's quick & easy.

how to get the country ?

P: n/a
from the IP of the request ?
Nov 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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_RAN GE )"
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
"Lloyd Dupont" <ll***@RemoveIfNotSpamming.galador.net> wrote in message
news:#h**************@TK2MSFTNGP09.phx.gbl...
from the IP of the request ?

Nov 17 '05 #2

P: n/a
"Ravikanth[MVP]" <dv*********@hotmail.com> wrote in message
news:03****************************@phx.gbl...
Hi

Check out this link
http://www.webmasterworld.com/forum13/1030.htm


I wonder how reliable this sort of thing is, given proxies and such. If
there are no RFCs which require than an IP address be tied to a country,
then perhaps you shouldn't depend on things like this for anything
important.
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com
Nov 17 '05 #3

P: n/a
"Alex K" <al*********@hotmail.com> wrote in message
news:ux**************@TK2MSFTNGP12.phx.gbl...
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?
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com
Nov 17 '05 #4

P: n/a
Yes but the is no database records about that.

"John Saunders" <jo***********@surfcontrol.com> wrote in message
news:#v**************@TK2MSFTNGP09.phx.gbl...
"Alex K" <al*********@hotmail.com> wrote in message
news:ux**************@TK2MSFTNGP12.phx.gbl...
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?
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com

Nov 17 '05 #5

P: n/a
"Alex K" <al*********@hotmail.com> wrote in message
news:eP**************@TK2MSFTNGP12.phx.gbl...
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.
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com
"John Saunders" <jo***********@surfcontrol.com> wrote in message
news:#v**************@TK2MSFTNGP09.phx.gbl...
"Alex K" <al*********@hotmail.com> wrote in message
news:ux**************@TK2MSFTNGP12.phx.gbl...
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?
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com


Nov 17 '05 #6

P: n/a
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

al**********@mailbits.com

"John Saunders" <jo***********@surfcontrol.com> wrote in message
news:Ov*************@TK2MSFTNGP09.phx.gbl...
"Alex K" <al*********@hotmail.com> wrote in message
news:eP**************@TK2MSFTNGP12.phx.gbl...
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.
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com
"John Saunders" <jo***********@surfcontrol.com> wrote in message
news:#v**************@TK2MSFTNGP09.phx.gbl...
"Alex K" <al*********@hotmail.com> wrote in message
news:ux**************@TK2MSFTNGP12.phx.gbl...
> 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?
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com



Nov 17 '05 #7

P: n/a
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 !
"John Saunders" <jo***********@surfcontrol.com> a écrit dans le message de
news:OQ**************@TK2MSFTNGP09.phx.gbl...
Alex, I'm not the original poster. He was asking how to get the country from the IP address. I'm the one saying that, unless there's some new RFC I
haven't heard about, you cannot reliably get the country from the IP
address. You may be able to guess at a country from the IP address, but it
would only be a guess.

Now, a guess is good enough for some applications, especially if it's
difficult to prove that the guess is wrong. But, coming from a Networking
background as I do, it's pretty damned unlikely you'll ever find me misusing an IP address that way.

My suggestion to people who want to know the location from which a request
came is that they should ask the requesting entity where it is located. Ask the user for his address, for instance, or for the address of his company.
If you need the location to be accurate, then you need to get GPS
information or location information from the Cellular Telephone
infrastructure.

Those are things which were intended to communicate location - an IP address was intended for a totally different purpose. Even the registries discussed elsewhere in this thread only record the "location" corresponding to the IP address in the sense that they record the location of the responsible person in the requesting entity. They record nothing at all about the location of
hosts which might happen to be using some of those IP addresses at some
particular time.

--
John Saunders
Internet Engineer
jo***********@surfcontrol.com
"Alex K" <al*********@hotmail.com> wrote in message
news:uN*************@TK2MSFTNGP09.phx.gbl...
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

al**********@mailbits.com

"John Saunders" <jo***********@surfcontrol.com> wrote in message
news:Ov*************@TK2MSFTNGP09.phx.gbl...
"Alex K" <al*********@hotmail.com> wrote in message
news:eP**************@TK2MSFTNGP12.phx.gbl...
> 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.
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com

> "John Saunders" <jo***********@surfcontrol.com> wrote in message
> news:#v**************@TK2MSFTNGP09.phx.gbl...
> > "Alex K" <al*********@hotmail.com> wrote in message
> > news:ux**************@TK2MSFTNGP12.phx.gbl...
> > > 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? > > --
> > John Saunders
> > Internet Engineer
> > jo***********@surfcontrol.com
> >
> >
>
>



Nov 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.