How to get Location informations from IP address.

C

Cihan

Hello,
I am looking for a .Net code which finds location information (country ,
city, streetname, postcode) for a specific IP-address.

Maybe there is webservice to do this. It is also can be usefull.

Best Regards.
 
A

Arne Vajhøj

Cihan said:
I am looking for a .Net code which finds location information (country ,
city, streetname, postcode) for a specific IP-address.

Maybe there is webservice to do this. It is also can be usefull.

Best Regards.

There are two separate problems.

1) getting the data
2) getting the code to read the data

You can pay one of the commercial providers (Quova, Akamai etc.)
and they will give you both data and code.

There are a couple of places where data are freely available
(maxmind and ip2country). The data either does not include
city and below level or are not that good at the city and below level).

The code is trivial (I have C# code for maxmind and ip2country
data if you are interested).

Arne
 
S

Scott M.

IP's don't represent the information you want. IP's are blocks of numbers
that are assigned to ISP's to then assign to their customers.

-Scott
 
G

Guest

Hello,
I am looking for a .Net code which finds location information (country ,
city, streetname, postcode) for a specific IP-address.

Maybe there is webservice to do this. It is also can be usefull.

Best Regards.

As Arne already suggested, look at maxmind and ip2country and you will
understand how it works and what information you will be able to
obtain

Examples:

http://www.eggheadcafe.com/articles/20051109.asp
http://forum.maxmind.com/viewtopic.php?t=1151
http://www.codeproject.com/KB/aspnet/aspxcode_net.aspx
 
C

Cihan

Thank you very much for your helps guys.

I have used this code and it is working fine. for your informations.


public class LocationInfo
{
public float Latitude { get; set; }
public float Longitude { get; set; }
public string CountryName { get; set; }
public string CountryCode { get; set; }
public string Name { get; set; }
}
public LocationInfo GetLocationInfo(string ipParam)
{
LocationInfo result = null;
IPAddress i = System.Net.IPAddress.Parse(ipParam);
string ip = i.ToString();
string r;
using (var w = new WebClient())
{
r =
w.DownloadString(String.Format("http://api.hostip.info/?ip={0}&position=true",
ip));
}


var xmlResponse = XDocument.Parse(r);
var gml = (XNamespace)"http://www.opengis.net/gml";
var ns = (XNamespace)"http://www.hostip.info/api";

try
{
result = (from x in xmlResponse.Descendants(ns +
"Hostip")
select new LocationInfo
{
CountryCode = x.Element(ns +
"countryAbbrev").Value,
CountryName = x.Element(ns +
"countryName").Value,
Latitude = float.Parse(x.Descendants(gml +
"coordinates").Single().Value.Split(',')[0]),
Longitude = float.Parse(x.Descendants(gml
+ "coordinates").Single().Value.Split(',')[1]),
Name = x.Element(gml + "name").Value
}).SingleOrDefault();
}
catch (NullReferenceException)
{
//Looks like we didn't get what we expected.
}

return result;
}
 
S

Scott M.

Again, an IP does not contain the information you seek to extract from it.
It's not meant to reprensent a physical location, although it *may* contain
regional information. But, even that is not reliable.

-Scott


Cihan said:
Thank you very much for your helps guys.

I have used this code and it is working fine. for your informations.


public class LocationInfo
{
public float Latitude { get; set; }
public float Longitude { get; set; }
public string CountryName { get; set; }
public string CountryCode { get; set; }
public string Name { get; set; }
}
public LocationInfo GetLocationInfo(string ipParam)
{
LocationInfo result = null;
IPAddress i = System.Net.IPAddress.Parse(ipParam);
string ip = i.ToString();
string r;
using (var w = new WebClient())
{
r =
w.DownloadString(String.Format("http://api.hostip.info/?ip={0}&position=true",
ip));
}


var xmlResponse = XDocument.Parse(r);
var gml = (XNamespace)"http://www.opengis.net/gml";
var ns = (XNamespace)"http://www.hostip.info/api";

try
{
result = (from x in xmlResponse.Descendants(ns +
"Hostip")
select new LocationInfo
{
CountryCode = x.Element(ns +
"countryAbbrev").Value,
CountryName = x.Element(ns +
"countryName").Value,
Latitude = float.Parse(x.Descendants(gml
+ "coordinates").Single().Value.Split(',')[0]),
Longitude = float.Parse(x.Descendants(gml
+ "coordinates").Single().Value.Split(',')[1]),
Name = x.Element(gml + "name").Value
}).SingleOrDefault();
}
catch (NullReferenceException)
{
//Looks like we didn't get what we expected.
}

return result;
}



Cihan said:
Hello,
I am looking for a .Net code which finds location information (country ,
city, streetname, postcode) for a specific IP-address.

Maybe there is webservice to do this. It is also can be usefull.

Best Regards.
 
A

Arne Vajhøj

Scott said:
> IP's don't represent the information you want. IP's are blocks of numbers
> that are assigned to ISP's to then assign to their customers.

True.

But then the ISP's allocate them to companies or home
users within a very limited geographical area.

So it is indeed possible to locate people based on
IP with a reasonable high probablity.

Arne
 
A

Arne Vajhøj

Mark said:
As has already been correctly pointed out, this is an almost pointless
exercise.

As has been pointed out incorrectly that is.

Geo location is a service provided by several serious
companies and used by thousands of customers worldwide.

It is not 100% reliable but still valuable in many contexts.

Arne
 
S

Scott M.

I don't see how you can say that. I have a static IP provided by my ISP and
if I wanted to use it on a machine at my vacation home in another state, I
could.

Just because an IP is issued in a certain locale, doesn't mean it will be
used in that locale.

And, there is nothing in the IP that identifies your city, street and house
number (which the OP says he wants).

-Scott
 
A

Arne Vajhøj

Scott said:
> I don't see how you can say that. I have a static IP provided by my ISP and
> if I wanted to use it on a machine at my vacation home in another state, I
> could.

Sure. But your ISP will not route traffic to that IP to
your vacation home.
> Just because an IP is issued in a certain locale, doesn't mean it will be
> used in that locale.

It is not where it is issued to. It is where the ISP's router send
the traffic to.
> And, there is nothing in the IP that identifies your city, street and house
> number (which the OP says he wants).

The lower granularity the less reliable the result is.

Country is very good. State is reasonable. Region and city are
not that good. Street would be rare to get correct. House number
no chance (but the the OP did *not* ask for house number).

Arne
 
S

Scott M.

Forgive my ignorance on this, but my understanding is that when an ISP needs
to "route" a message to an IP, they do not need to do anything special
(anything that relates to a physical location), they simply need to make
sure that the packets are addressed correctly, which is what TCP/IP ensures.

Given this, what difference does it make if I pack up my machine and take it
to my vacation home? The IP would still be the same (remember, I'm talking
about static IP's), so my machine would still respond when a message is
broadcast to it.

-Scott
 
J

Juan T. Llibre

re:
!> Forgive my ignorance on this, but my understanding is that when an ISP needs
!> to "route" a message to an IP, they do not need to do anything special
!> (anything that relates to a physical location), they simply need to make
!> sure that the packets are addressed correctly, which is what TCP/IP ensures.

Correct, but that has nothing to do with the problem at hand.
Routing to specific IPs must be programmed. It doesn't happen automagically.

re:
!> what difference does it make if I pack up
!> my machine and take it to my vacation home?

Static IPs are assigned to phone line ports at your ISP's switching facilities.

If you pack up your machine and plug it into a different phone line a few miles away,
you will not get the same static IP you get when you plug it into the phone line
which is programmed to route the assigned static IP to your home phone.

If the static IP is programmed for a specific phone line, then TCP/IP can find it.
Otherwise it cannot.




===============
 
A

Arne Vajhøj

Scott said:
> Forgive my ignorance on this, but my understanding is that when an ISP needs
> to "route" a message to an IP, they do not need to do anything special
> (anything that relates to a physical location), they simply need to make
> sure that the packets are addressed correctly, which is what TCP/IP
ensures.

They need to have routing tables in their routers telling them
where to send your IP address.
> Given this, what difference does it make if I pack up my machine and take it
> to my vacation home? The IP would still be the same (remember, I'm talking
> about static IP's), so my machine would still respond when a message is
> broadcast to it.

The IP packets to your PC is not broadcasted to all PC's on
the ISP's network - they are routed to your PC.

Arne
 

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

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top