本文提供了兩個簡單的腳本showipaddr
(在Bash和Python中),以快速檢索Linux中的私人(本地)和公共IP地址。儘管Linux提供了ip
和nmcli
之類的內置命令,但這些腳本提供了一種簡化的方法來僅獲取基本IP信息。
這些腳本允許您:
這兩個腳本都在GitHub上可用。下載後,您需要使它們可執行,並可選地將其移至系統路徑以輕鬆訪問。
使用bash腳本( showipaddr.sh
):
此腳本需要Bash, curl
和jq
。如果需要,將提供有關這些的安裝說明。
git clone https://gist.github.com/09259a3da0e7190775d16aadef14580b.git showipaddr
cd showipaddr/
chmod x showipaddr.sh
sudo mv showipaddr.sh /usr/local/bin/showipaddr
showipaddr
該腳本提示您選擇是否顯示本地IP,公共IP或兩者兼而有之。
示例輸出(兩者顯示):
<code>Select the information to display: 1. Local IP 2. Public IP 3. Both Local and Public IP Enter your choice (1/2/3): 3 ------------------------------------------------------ Local Network Information: Hostname : [hostname] Local IPv4 Address : [IPv4 address] Local IPv6 Address : [IPv6 address] Router IP Address : [router IP] DNS Server : [DNS server] ------------------------------------------------------ ------------------------------------------------------ Public IP Information: IP Address : [public IP address] ISP : [ISP] City : [City] Region : [Region] Country : [Country] Coordinates : [Latitude], [Longitude] ------------------------------------------------------</code>
使用Python腳本( showipaddr.py
):
此腳本需要Python 3和requests
庫( pip install requests
)。它還檢查jq
,但不直接使用它。
git clone https://gist.github.com/27276f43e980aa3a468c4b39680a68ee.git showipaddr
cd showipaddr/
python3 showipaddr.py
該腳本提供與Bash腳本相同的選擇選項。
這兩個腳本都提供了一種訪問重要的IP地址信息的方便方法。選擇最適合您的系統和偏好的腳本。
以上是如何使用ShowipAddr腳本在Linux中顯示本地和公共IP地址的詳細內容。更多資訊請關注PHP中文網其他相關文章!