Home > System Tutorial > LINUX > How To Display Local And Public IP Address In Linux Using Showipaddr Script

How To Display Local And Public IP Address In Linux Using Showipaddr Script

尊渡假赌尊渡假赌尊渡假赌
Release: 2025-03-20 09:06:13
Original
801 people have browsed it

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:

  • View local network details: Obtain your system's hostname, IPv4 and IPv6 addresses, gateway (router) address, and DNS server information.
  • Determine your public IP address: Display your public IP, along with ISP, city, region, country, and coordinates.

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.

  1. Download: git clone https://gist.github.com/09259a3da0e7190775d16aadef14580b.git showipaddr
  2. Navigate: cd showipaddr/
  3. Make executable: chmod x showipaddr.sh
  4. Move to PATH (optional): sudo mv showipaddr.sh /usr/local/bin/showipaddr
  5. Run: 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>
Copy after login

How To Display Local And Public IP Address In Linux Using Showipaddr Script

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.

  1. Download: git clone https://gist.github.com/27276f43e980aa3a468c4b39680a68ee.git showipaddr
  2. Navigate: cd showipaddr/
  3. Run: python3 showipaddr.py

The script offers the same selection options as the Bash script.

How To Display Local And Public IP Address In Linux Using Showipaddr 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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template