一、 curl查询公网出口IP
不管是在家里还是办公室,或者是公司的主机,很多时候都是在内网中,也就是说很多都是通过 NAT上网的,有时候需要查询下出口的公网IP,如果有浏览器,可以用百度或者google搜 ip
这个关键词得到公网IP。
# curl ipinfo.io { "ip": "114.110.1.38", "hostname": "No Hostname", "city": "Beijing", "region": "Beijing Shi", "country": "CN", "loc": "39.9289,116.3883", "org": "AS4808 CNCGROUP IP network China169 Beijing Province Network" }% # curl ip.cn 当前 IP:114.110.1.38 来自:北京市 xxx北京分公司 # curl cip.cc IP : 114.110.1.38 地址 : 中国 北京市 数据二 : 北京市 | xxx北京分公司 URL : http://www.cip.cc/114.110.1.38 # curl myip.ipip.net 当前 IP:114.110.1.38 来自于:中国 北京 北京 联通/电信 # curl ifconfig.me 114.110.1.38 # curl http://members.3322.org/dyndns/getip 114.110.1.38
二、go写成可执行工具
package main import ( "io/ioutil" "net/http" "os" ) func main() { res, _ := http.Get("https://myip.ipip.net") ip, _ := ioutil.ReadAll(res.Body) os.Stdout.Write(ip) }