獲取網站ip(Linux)

背景在自己的筆記本上面裝Linux,上網一般都是通過wifi上面,不是直接配置外網IP的,有時候連接到遠程服務器的時候,需要知道自己的外網IP的哪個,進行添加白名單。ifconfig.me這個網站提供瞭,對應的api來獲取對應的外網IP信息,及請求客戶端的信息,可以通過瀏覽器訪問ifconfig.me找到下面的命令幫助,執行對應的curl請求,就可以獲取到信息$ curl ifconfig.me ⇒ 1.62.24.94
$ curl ifconfig.me/ip ⇒ 1.62.24.94
$ curl ifconfig.me/host ⇒ unavailable
$ curl ifconfig.me/ua ⇒ Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36
$ curl ifconfig.me/port ⇒ 15294
$ curl ifconfig.me/lang ⇒ zh-CN,zh;q=0.9,en;q=0.8
$ curl ifconfig.me/keepalive ⇒
$ curl ifconfig.me/connection ⇒
$ curl ifconfig.me/encoding ⇒ gzip, deflate, br
$ curl ifconfig.me/mime ⇒ text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
$ curl ifconfig.me/charset ⇒
$ curl ifconfig.me/via ⇒ 1.1 google
$ curl ifconfig.me/forwarded ⇒ 1.62.24.94, 213.62.20.194
$ curl ifconfig.me/all ⇒ ip_addr: 1.62.24.94
remote_host: unavailable
user_agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36
port: 15294
language: zh-CN,zh;q=0.9,en;q=0.8
referer: https://blog.csdn.net/
connection:
keep_alive:
method: GET
encoding: gzip, deflate, br
mime: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
charset:
via: 1.1 google
forwarded: 1.62.24.94, 213.62.20.194
$ curl ifconfig.me/all.xml ⇒ <info> <ip_addr>1.62.24.94</ip_addr> <remote_host>unavailable</remote_host> <user_agent>Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36</user_agent> <port>15294</port> <language>zh-CN,zh;q=0.9,en;q=0.8</language> <referer>https://blog.csdn.net/</referer> <connection></connection> <keep_alive></keep_alive> <method>GET</method> <encoding>gzip, deflate, br</encoding> <mime>text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3</mime> <charset></charset> <via>1.1 google</via> <forwarded>1.62.24.94, 213.62.20.194</forwarded> </info>
$ curl ifconfig.me/all.json ⇒ {“ip_addr”:”1.62.24.94″,”remote_host”:”unavailable”,”user_agent”:”Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36″,”port”:15294,”language”:”zh-CN,zh;q=0.9,en;q=0.8″,”referer”:”https://blog.csdn.net/”,”method”:”GET”,”encoding”:”gzip, deflate, br”,”mime”:”text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3″,”via”:”1.1 google”,”forwarded”:”1.62.24.94, 213.62.20.194″}
ip.cn上面的網址提供的內容雖然很多,但是比較慢,有時候還請求失敗,可以使用ip.cn提供的服務進行查詢curl https://ip.cn
{“ip”: “112.48.22.57”, “country”: “福建省廈門市”, “city”: “移動”}


本文出自快速备案,转载时请注明出处及相应链接。

本文永久链接: https://www.xiaosb.com/beian/51774/