Get public/external IP address?

Using C#, With webclient its a short one.

public static void Main(string[] args)
{
    string externalIpString = new WebClient().DownloadString("http://icanhazip.com").Replace("\\r\\n", "").Replace("\\n", "").Trim();
    var externalIp = IPAddress.Parse(externalIpString);

    Console.WriteLine(externalIp.ToString());
}

Command Line (works on both Linux and Windows)

wget -qO- http://bot.whatismyipaddress.com

OR

curl http://ipinfo.io/ip

Leave a Comment