Quero pegar o Localização de um IP externo e para isso utilizei um site em que simplesmente coloco o IP que desejo e ele retorna o XML com as informações.
Exemplo:
freegeoip.net/xml/4.2.2.2
ou seja:
freegeoip.net/[tipo]/[ip]
Para isso estou pegando todos os caracteres desse site e tentando trabalhar com uma string contendo um XML dentro e retornando o que eu quero:
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;
}
Já tentei tirar os \n\t
que aparecem na string site, já tentei trabalhar com outras funções da XElement
e também já procurei por outras classes porém a maioria trabalha com arquivo e não com string.