我想在雙擊 .cmd 或 .bat 檔案時在 Window 的命令提示符中獲取我的外部 IP 地址的位置。
據我所知,這至少需要在 CMD 中執行兩個步驟:
第 1 步:獲取我的外部 IP:
curl ip-adresim.app
輸出:
216.58.194.46
第 2 步:獲取該 IP 的位置:
curl ipinfo.io/216.58.194.46
輸出:
{“ip”:“216.58.194.46”,“主機名”:“dfw25s12-in-f46.1e100.net”,“城市”:“舊金山”,“地區”:“加利福尼亞”,“國家”:“美國", "loc": "37.7749,-122.4194", "org": "AS15169 Google LLC", "postal": "94102", "timezone": "America/Los_Angeles", "readme": "https:// ipinfo.io/missingauth" }
我必須通過一個公共變數連接這兩個步驟,才能使它成為一個自動化腳本,對吧。
但是怎么做?
uj5u.com熱心網友回復:
如果您想一步捕獲此資訊,我已經使用了 ipinfo.io/city:
for /f "tokens=*" %%g in ('%__APPDIR__%curl.exe -s ipinfo.io/city') do set "_myLocation=%%g"
if defined _myLocation echo %_myLocation%
這是假設您只是在尋找城市。我不確定您所說的“輸入文本”是什么意思,但如果您想要 IP、城市和國家/地區,您可以執行以下操作:
for /f "tokens=*" %%g in ('%__APPDIR__%curl.exe -s ipinfo.io/ip') do set "_myIP=%%g"
for /f "tokens=*" %%g in ('%__APPDIR__%curl.exe -s ipinfo.io/city') do set "_myCity=%%g"
for /f "tokens=*" %%g in ('%__APPDIR__%curl.exe -s ipinfo.io/country') do set "_myCountry=%%g"
if defined _myIP echo External IP: %_myIP%
if defined _myCity echo City: %_myCity%
if defined _myCountry echo Country: %_myCountry%
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/470185.html
