I want to get the location of an external IP and for that I used a site where I simply put the IP that I want and it returns the XML with the information.
Example:
freegeoip.net/xml/4.2.2.2
that is:
freegeoip.net/[tipo]/[ip]
For this I'm getting all the characters from this site and trying to work with a string containing an XML inside and returning what I want:
public static string getLocationIPAddress()
{
string country = null;
string state = null;
string city = null;
System.Net.WebClient t = new System.Net.WebClient();
string site = t.DownloadString("https://freegeoip.net/xml/"
+ getExternIPAdrress());
XElement xml = XElement.Parse(site);
country = xml.Attribute("CountryName").Value;
state = xml.Attribute("RegionName").Value;
city = xml.Attribute("City").Value;
return "País: " + country + "Estado: " + state + "Cidade: " + city;
}
I've already tried to get the \n\t
that appears in the string site, I've tried to work with other functions of XElement
and I've also looked for other classes, but most work with file and not with string.