Geeks With Blogs
Peter Stathakos - Stack Of Toast Microsoft, .NET and Life in General

Duncan Mackenzie posted about people asking how to obtain the IP address of your internet connection. He created a web service for this task including the VB code to access it.

Here is my C# version of the code,

1. First you need to add a web reference to the web service IPInfo.asmx

2. And now the code (all prettied up for your easy perusal)...

string myIPAddress;

//Show Waitcursor while web service is being called
Cursor.Current = Cursors.WaitCursor;

//Create instance of web service and obtain IP address
net.duncanmackenzie.www.IPInfo IP = new net.duncanmackenzie.www.IPInfo();
myIPAddress = IP.GetMyIP();

//Show normal cursor
Cursor.Current = Cursors.Default;

//Display IP adddress
System.Windows.Forms.MessageBox.Show("Your IP address is " + myIPAddress);

 

This can be done just as easily in a console app if desired.
Thanks to Duncan for the code and web service.


Currently listening to: Crush (1980 Me) - (04:00)
Darren Hayes, Spin Posted on Tuesday, March 1, 2005 3:46 PM .NET | Back to top


Comments on this post: IP Address From a Web Service

# re: IP Address From a Web Service
Requesting Gravatar...
where can i find the webservice ? after I click on IPInfo.asmx I get a page showing errors
Left by ashish on Feb 28, 2007 1:15 PM

# re: IP Address From a Web Service
Requesting Gravatar...
Hi Ashish,

It looks like the web service is no longer running, I guess Duncan took it down sorry.
Left by Peter on Feb 28, 2007 9:47 PM

Your comment:
 (will show your gravatar)
 


Copyright © Peter Stathakos | Powered by: GeeksWithBlogs.net | Join free