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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…