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 web service.

protected void Button1_Click(object sender, EventArgs e)
string xmlResult = null;
string url;
url = "" + 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();
if (doc.GetElementsByTagName("ReturnCode").Item(0).InnerText.ToString()== "0")
Label1.Text = "Invalid IP Address please enter correct address";
Label2.Text = "";
Label3.Text = "";
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#

I hope this Article is help to you get IP details.


  • IPTrack_Web_Services (42822-151019-IPTrace.rar)
  • Comments

    Author: asdfg26 May 2011 Member Level: Gold   Points : 0

    Thanks a lot for sharing. Is it possible to get the location also. like Hyderabad, Pune, ...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: