获取公共/外部 IP 地址? [英] Get public/external IP address?

查看:36
本文介绍了获取公共/外部 IP 地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法获取或找到有关查找路由器公共 IP 的信息?这是因为它不能通过这种方式完成并且必须从网站上获取吗?

I cant seem to get or find information on finding my routers public IP? Is this because it cant be done this way and would have to get it from a website?

推荐答案

使用 C#,使用 webclient 很短.

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());
}

命令行(适用于 Linux 和 Windows)

Command Line (works on both Linux and Windows)

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

curl http://ipinfo.io/ip

这篇关于获取公共/外部 IP 地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆