Created
December 13, 2014 02:07
-
-
Save woodss/be1a28be873b2221b893 to your computer and use it in GitHub Desktop.
IPFreely - Simple C# Console Application to get IP address from an external web service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace IPfreely | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine(GetExternalIPAddress()); | |
Console.ReadLine(); | |
} | |
private static string GetExternalIPAddress() | |
{ | |
using (WebClient client = new WebClient()) | |
{ | |
try | |
{ | |
return "You IP address is: " + client.DownloadString("http://wtfismyip.com/text"); | |
} | |
catch (Exception e) | |
{ | |
return "Your IP address could not be resolved because " + e.Message; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment