Hey guys well my idea is simple, I will get location information from an IP address (proxy at example) with Utrace API.
look at this code (thanks google)
public static string GetLocation(string IP)
{
var location = "";
List<string> HTML_code = new List<string>();
WebRequest request = WebRequest.Create("http://xml.utrace.de/?query=" + IP);
using (WebResponse response = request.GetResponse())
using (StreamReader stream = new StreamReader(response.GetResponseStream()))
{
string line;
while ((line = stream.ReadLine()) != null)
{
HTML_code.Add(line);
}
}
location = (HTML_code[296].Replace("<td><font size=\"-1\">", "")).Replace("</font></td>", "");
return location;
}
OK but the output from the utrace API is the following:
<?xml version="1.0" encoding="iso-8859-1"?>
<results>
<result>
<ip>188.40.16.134</ip>
<host></host>
<isp>Hetzner Online AG Pagedesign</isp>
<org>Hetzner Online AG Pagedesign</org>
<region>Koblenz</region>
<countrycode>DE</countrycode>
<latitude>50.349998474121</latitude>
<longitude>7.5999999046326</longitude>
<queries>8</queries>
</result>
</results>
My XML skill is not the best I hope you guys can help me to edit this line:
location = (HTML_code[296].Replace("<td><font size=\"-1\">", "")).Replace("</font></td>", "");
I will an output like this:
Hetzner Online AG Pagedesign : Koblenz
and not
<?xml version="1.0" encoding="iso-8859-1"?>
<results>
<result>
<ip>188.40.16.134</ip>
<host></host>
<isp>Hetzner Online AG Pagedesign</isp>
<org>Hetzner Online AG Pagedesign</org>
<region>Koblenz</region>
<countrycode>DE</countrycode>
<latitude>50.349998474121</latitude>
<longitude>7.5999999046326</longitude>
<queries>8</queries>
</result>
</results>
Thanks in advance for your help
Edit:
My new code is following:
public static void getloc(string ip)
{
var location = "";
var wc = new WebClient();
location = wc.DownloadString("http://xml.utrace.de/?query=" + ip);
location = location.Replace("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>", "").Replace("<results>", "").Replace("<result>", "")
.Replace("<ip></ip>", "").Replace("<org></org>", "").Replace("<latitude></latitude>", "").Replace("<longitude></longitude>", "").Replace("<queries>*</queries>", "")
.Replace("</result>", "").Replace("</results>", "");
Console.WriteLine(location);
}
the output is then :
<ip>212.19.62.76</ip>
<host>1</host>
<isp>Plus.line AG</isp>
<org>ANW GmbH & Co. KG</org>
<region>Bechhofen</region>
<countrycode>DE</countrycode>
<latitude>49.150001525879</latitude>
<longitude>10.550000190735</longitude>
<queries>6</queries>
How can I get an output like
Plus.line AG ANW GmbH & Co. KG Bechhofen
Greets and thanks
Load the XML into an
XmlDocumentand parse it properly.