This article provides two simple scripts, showipaddr
(in Bash and Python), to quickly retrieve your private (local) and public IP addresses in Linux. While Linux offers built-in commands like ip
and nmcli
, these scripts offer a streamlined approach for obtaining only the essential IP information.
These scripts allow you to:
Both scripts are available on GitHub. After downloading, you'll need to make them executable and optionally move them to your system's PATH for easy access.
Using the Bash Script (showipaddr.sh
):
This script requires Bash, curl
, and jq
. Installation instructions for these are provided if needed.
git clone https://gist.github.com/09259a3da0e7190775d16aadef14580b.git showipaddr
cd showipaddr/
chmod x showipaddr.sh
sudo mv showipaddr.sh /usr/local/bin/showipaddr
showipaddr
The script prompts you to select whether to display local IP, public IP, or both.
Example output (showing both):
<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>
Using the Python Script (showipaddr.py
):
This script requires Python 3 and the requests
library (pip install requests
). It also checks for jq
, but doesn't directly use it.
git clone https://gist.github.com/27276f43e980aa3a468c4b39680a68ee.git showipaddr
cd showipaddr/
python3 showipaddr.py
The script offers the same selection options as the Bash script.
Both scripts provide a convenient way to access crucial IP address information. Choose the script that best suits your system and preferences.
The above is the detailed content of How To Display Local And Public IP Address In Linux Using Showipaddr Script. For more information, please follow other related articles on the PHP Chinese website!