获取本地公网IP地址的方法

适用场景:

服务器地址为net映射地址,本机ifconfig无法直接获取映射的公网地址。

方法1:

[root@TiaoBan-1 nidongde]# curl http://ifconfig.me
50.1xx.2xx.18

ifconfig.me的地址为日本地址,访问可能比较慢。

方法2:

[root@TiaoBan-1 nidongde]# curl http://www.net.cn/static/customercare/yourip.asp 2>/dev/null|grep h2
          IP<h2>50.1xx.2xx.18</h2>

相关网站:
网址1:http://ifconfig.me(访问速度慢)
网址2:http://www.net.cn/static/customercare/yourip.asp推荐使用,访问速度快

猜你喜欢

转载自www.cnblogs.com/pzzning/p/9198382.html