473,655 Members | 3,056 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to get the country ?

from the IP of the request ?
Nov 17 '05 #1
7 1913
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(ByVa l 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))).To String
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(ByVa l 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(".".ToCha rArray)
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("r ipencc|") Then
line = s.Split("|".ToC harArray)
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,I P_RANGE )"
sql &= " VALUES ('RIPENCC',SYSD ATE"
sql &= "," & _quote(line(1))
sql &= "," & ipFrom
sql &= "," & ipTo
sql &= "," & _quote(ipFromSt r)
sql &= "," & _quote(ipToStr)
sql &= "," & range
sql &= " )"

Execute_DML(sql , Cnn)
End If
End If
"Lloyd Dupont" <ll***@RemoveIf NotSpamming.gal ador.net> wrote in message
news:#h******** ******@TK2MSFTN GP09.phx.gbl...
from the IP of the request ?

Nov 17 '05 #2
"Ravikanth[MVP]" <dv*********@ho tmail.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***********@s urfcontrol.com
Nov 17 '05 #3
"Alex K" <al*********@ho tmail.com> wrote in message
news:ux******** ******@TK2MSFTN GP12.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***********@s urfcontrol.com
Nov 17 '05 #4
Yes but the is no database records about that.

"John Saunders" <jo***********@ surfcontrol.com > wrote in message
news:#v******** ******@TK2MSFTN GP09.phx.gbl...
"Alex K" <al*********@ho tmail.com> wrote in message
news:ux******** ******@TK2MSFTN GP12.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***********@s urfcontrol.com

Nov 17 '05 #5
"Alex K" <al*********@ho tmail.com> wrote in message
news:eP******** ******@TK2MSFTN GP12.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***********@s urfcontrol.com
"John Saunders" <jo***********@ surfcontrol.com > wrote in message
news:#v******** ******@TK2MSFTN GP09.phx.gbl...
"Alex K" <al*********@ho tmail.com> wrote in message
news:ux******** ******@TK2MSFTN GP12.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***********@s urfcontrol.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**********@ma ilbits.com

"John Saunders" <jo***********@ surfcontrol.com > wrote in message
news:Ov******** *****@TK2MSFTNG P09.phx.gbl...
"Alex K" <al*********@ho tmail.com> wrote in message
news:eP******** ******@TK2MSFTN GP12.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***********@s urfcontrol.com
"John Saunders" <jo***********@ surfcontrol.com > wrote in message
news:#v******** ******@TK2MSFTN GP09.phx.gbl...
"Alex K" <al*********@ho tmail.com> wrote in message
news:ux******** ******@TK2MSFTN GP12.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***********@s urfcontrol.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******** ******@TK2MSFTN GP09.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***********@s urfcontrol.com
"Alex K" <al*********@ho tmail.com> wrote in message
news:uN******** *****@TK2MSFTNG P09.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**********@ma ilbits.com

"John Saunders" <jo***********@ surfcontrol.com > wrote in message
news:Ov******** *****@TK2MSFTNG P09.phx.gbl...
"Alex K" <al*********@ho tmail.com> wrote in message
news:eP******** ******@TK2MSFTN GP12.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***********@s urfcontrol.com

> "John Saunders" <jo***********@ surfcontrol.com > wrote in message
> news:#v******** ******@TK2MSFTN GP09.phx.gbl...
> > "Alex K" <al*********@ho tmail.com> wrote in message
> > news:ux******** ******@TK2MSFTN GP12.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***********@s urfcontrol.com
> >
> >
>
>



Nov 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
5523
by: T0MA | last post by:
How can I view visitors country using php/apache?
11
8442
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? Thanks
9
9587
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. I know how to show the information based on another part of the page, but I don't know how to make a map of a country clickable ( meaning, clicking different part of the map to show info on the page). How can I make a map of a country with...
2
3549
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 system that will identify where the users are coming from based on their IP address, and for this project I would really like to replace the English country list with a list of the country in the local language. I'm been around on
4
9472
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. Do somebody know how to get them in C#.
7
7154
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
1827
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 | +-------------+-----------+ |ghanistan | Kabul |lbania | Tirane
4
1965
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 really comprehensive country list (which is great), but I'm a little stuck as to what to do for the next level down in the hierarchy.
1
5456
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 email and auto respond the email. My Issue is, i am receiving some email with country code as email id(say <country code><phonenumber>@<carrier.com> and some without country code as email id <numberphonenumber>@<carrier.com> Is...
0
8380
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8816
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8710
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8598
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4299
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2721
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1928
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1598
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.