当前位置: 移动技术网 > 网络运营>服务器>Linux > Linux下查询外网IP的几种方法总结

Linux下查询外网IP的几种方法总结

2019年04月24日  | 移动技术网网络运营  | 我要评论

linux下查询外网ip的几种方法总结

curl 纯文本格式输出:

curl icanhazip.com
curl ifconfig.me
curl curlmyip.com
curl ip.appspot.com
curl ipinfo.io/ip
curl ipecho.net/plain
curl www.trackip.net/i

 curl json格式输出:

curl ipinfo.io/json
curl ifconfig.me/all.json
curl www.trackip.net/ip?json (有点丑陋)

 curl xml格式输出:

curl ifconfig.me/all.xml

curl 得到所有ip细节 (挖掘机)

curl ifconfig.me/all

使用 dydns (当你使用 dydns 服务时有用)

curl -s 'http://checkip.dyndns.org' | sed 's/.*current ip address: \([0-9\.]*\).*/\1/g'
curl -s http://checkip.dyndns.org/ | grep -o "[[:digit:].]\+"
 

使用 wget 代替 curl

wget http://ipecho.net/plain -o - -q ; echo
wget http://observebox.com/ip -o - -q ; echo

 使用 host 和 dig 命令

如果有的话,你也可以直接使用 host 和 dig 命令。

host -t a dartsclink.com | sed 's/.*has address //'
dig +short myip.opendns.com @resolver1.opendns.com

 bash 脚本示例:

#!/bin/bash
public_ip=`wget http://ipecho.net/plain -o - -q ; echo`
echo $public_ip

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网