How to get IP address details using web service?
In this article I have explained about how to get Country Name or code based on the IP address of the system. This IP Track application is used web service and gives details of that IP. Here I collect IP address in the client side and show IP address details on the same page after click submit button.
How to get IP address using web services?
We can get Country name and country details with help of web service. In the below code I used www.webservicex.net/geoipservice.asmx web service.
protected void Button1_Click(object sender, EventArgs e)
{
string xmlResult = null;
string url;
url = "http://www.webservicex.net/geoipservice.asmx/GetGeoIP?IPAddress=" + TextBox1.Text + "";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader resStream = new StreamReader(response.GetResponseStream());
XmlDocument doc = new XmlDocument();
xmlResult = resStream.ReadToEnd();
doc.LoadXml(xmlResult);
if (doc.GetElementsByTagName("ReturnCode").Item(0).InnerText.ToString()== "0")
{
Label1.Text = "Invalid IP Address please enter correct address";
Label2.Text = "";
Label3.Text = "";
}
else
{
Label1.Text = "IP Address ofd your System " + doc.GetElementsByTagName("IP").Item(0).InnerText;
Label2.Text = "Country Name " + doc.GetElementsByTagName("CountryName").Item(0).InnerText;
Label3.Text = "Country code " + doc.GetElementsByTagName("CountryCode").Item(0).InnerText;
}
}
Source Code Detail:
Here with I have attached source code to get IP details. Download it and try to IP details and also if you like then add this application in your site side bar. This one is also help to increase your site traffic too.
Front End : ASP.NET
Code Behind : C#
Conclusion:
I hope this Article is help to you get IP details.
Thanks a lot for sharing. Is it possible to get the location also. like Hyderabad, Pune, ...