通过命令快速获取本机外网IP

下面几个链接都可以帮助我们获取到本机的外网IP,但是返回值稍有不同,有的返回纯净的IP(结尾有带换行的和不带换行的),有的携带一些其他内容,有的支持http和https,有的支持http或https,这里面ip.cn最TMD有意思,我在Mac上访问,返回HTML,在Linux上访问,返回JSON.

curl http://whatismyip.akamai.com
curl http[s]://icanhazip.com
curl http[s]://myip.dnsomatic.com
curl https://ip.cn
curl http[s]://myip.ipip.net
curl http://ip.d3vm.net

$ curl http://whatismyip.akamai.com
x.x.x.x无换行

$ curl https://icanhazip.com
x.x.x.x有换行

$ curl https://myip.dnsomatic.com
x.x.x.x无换行

$ curl https://ip.cn #Mac上访问Your IP: x.x.x.x


Please visit https://ip.cn for more functions.$ curl https://ip.cn #Linux上访问
{"ip": "x.x.x.x", "country": "北京市", "city": "联通"}

$ curl https://myip.ipip.net
当前 IP:x.x.x.x  来自于:中国 北京 北京  联通

$ curl http://ip.d3vm.net
IP: x.x.x.x
Reverse DNS: x.x.x.x