幾種在Linux下查詢外網IP的辦法。


幾種在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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM