1. 程式人生 > 實用技巧 >幾種Linux 查詢外網出口IP的方法

幾種Linux 查詢外網出口IP的方法

Curl 純文字格式輸出:

curlicanhazip.com
curlifconfig.me
curlcurlmyip.com
curlip.appspot.com
curlipinfo.io/ip
curlipecho.net/plain
curlwww.trackip.net/i

curl JSON格式輸出:

curlipinfo.io/jsoncurlifconfig.me/all.jsoncurlwww.trackip.net/ip?json(有點醜陋)

curl XML格式輸出:

curlifconfig.me/all.xml

curl 得到所有IP細節 (挖掘機)

curlifconfig.me/all

使用 DYDNS (當你使用 DYDNS 服務時有用)

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

使用 Wget 代替 Curl

wgethttp://ipecho.net/plain-O--q;echo
wgethttp://observebox.com/ip-O--q;echo

使用 host 和 dig 命令

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

host-tadartsclink.com|sed's/.*hasaddress//'
dig+shortmyip.opendns.com@resolver1.opendns.com

bash 指令碼示例:

#!/bin/bash
PUBLIC_IP=`wgethttp://ipecho.net/plain-O--q;echo`
echo$PUBLIC_IP

來源:承德SEO