幾種在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 命令。git

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
相關文章
相關標籤/搜索