473,396 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to get the country ?

from the IP of the request ?
Nov 17 '05 #1
7 1902
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
"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
"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
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
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: T0MA | last post by:
How can I view visitors country using php/apache?
11
by: abracad | last post by:
Hi Is there any (preferably free) PHP script that will identify the country of a visitor, thus allowing one page to be delivered to those from A, B and C, and another to those from X, Y and Z? ...
9
by: Lando Chez | last post by:
Hi I need a map of a country on which a region( part of the map) can be clicked ( or on mouseover) causing, on another part of the same page, the appearance of information regarding the region....
2
by: Zyron | last post by:
Hello! I'm developing a web page that has a goal of providing personal content, which means that all information should be written in their own language. I'm about to finish my Geo targeting...
4
by: Susanne Christe | last post by:
Hi all, I know how to use System.Globalization.RegionInfo, but I have problems to get the Numeric Country Code like this here: http://www.atmajaya.ac.id/Weblinks/KodeNegara.html ISO-3166. ...
7
by: Antoni Massó Mola | last post by:
Hi, I need to detect from which Country (City would be great) the user is connecting. Is there any free script for doing this in C#? Thanks
2
by: PRS | last post by:
Why does 'SELECT * FROM countries' truncate characters and SELECT country FROM countries does not ? mysql> SELECT * FROM countries; +-------------+-----------+ | country | capital |...
4
by: steve_barker333 | last post by:
Hi guys, I'm designing a web-site that will allow users to look up other people, based on certain criteria. The most important criterion is geographical location. I've managed to find a...
1
by: suresh_nsnguys | last post by:
Respected sir/madam, In My Application, users can send me an email with some keyword 'XXXX' to our mail server 'XXXX@xxxxx.com'.i am using imap_open() and other imap functions to read that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.