Subscribe to Subscribers
Talk to Webmaster Tony John

Online Members

baskar
More...


Resources » Code Snippets » ASP.NET WebForms

How to get IP address details using web service?


Posted Date:     Category: ASP.NET WebForms    
Author: Member Level: Diamond    Points: 7


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.

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





  • Did you like this resource? Share it with your friends and show your love!


    Responses to "How to get IP address details using web service?"
    Author: asdfg    26 May 2011Member Level: Gold   Points : 0
    Thanks a lot for sharing. Is it possible to get the location also. like Hyderabad, Pune, ...


    Feedbacks      

    Post Comment:




  • 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:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: How to get current currency exchange rate value using web services?
    Previous Resource: How to Avoid Re-Submitting Data on Page Refresh?
    Return to Resources
    Post New Resource
    Category: ASP.NET WebForms


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    How to get IP details using ASP.NET?  .  How to use web service?  .  How to get IP Details using Web service.  .  



    Follow us on Twitter: https://twitter.com/dotnetspider

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.