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.