Introduction
This article describes how to find the names of countries and cities using the IP address.
Using the code
The code is given below with explanations:
string IP = Request.ServerVariables["REMOTE_ADDR"];
XmlDocument doc = new XmlDocument();
doc.Load("http://www.showmyip.com/xml/?ip=" + IP);
XmlNodeList nodeLstCountry = doc.GetElementsByTagName("lookup_country");
XmlNodeList nodeLstCity = doc.GetElementsByTagName("lookup_city2");
IP = "Country :" + nodeLstCountry[0].InnerText +
" -- City :" + nodeLstCity[0].InnerText + "" + IP;
Response.Write(IP);
Page.Header.Title = "I am muslim before anything";