Skip to content

Instantly share code, notes, and snippets.

@woodss
Created December 13, 2014 02:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woodss/be1a28be873b2221b893 to your computer and use it in GitHub Desktop.
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
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