Portable IPv4 detection tool for Unix-like systems
ShowIP is a lightweight, portable, and POSIX-compliant shell tool that detects your public and local IPv4 addresses.
It is designed to work across multiple Unix-like systems including Linux, BSD, and macOS, while keeping dependencies minimal.
The script automatically detects available networking utilities (curl, wget, or fetch) and uses multiple IP services as failover providers to ensure reliable results.
ShowIP is particularly useful for:
- shell scripts
- automation workflows
- system diagnostics
- DevOps tooling
- CI/CD environments
- Detect Public IPv4
- Detect Local IPv4
- Automatic failover between multiple IP providers
- POSIX compliant shell script
- Extremely lightweight
- Zero external dependencies required
- Works on Linux, BSD, and macOS
- Optional JSON output for scripting
- VM / container safe local IP detection
- Overview
- Features
- Installation
- Usage
- Examples
- Output Formats
- How It Works
- Portability
- Dependencies
- Security Considerations
- Contributing
- License
git clone https://github.com/korayustundag/showip.git
cd showip
chmod +x showipsudo install -m 755 showip /usr/local/bin/showipNow you can run it anywhere:
showipcurl -O https://raw.githubusercontent.com/korayustundag/showip/main/showip
chmod +x showipshowip [options]| Option | Description |
|---|---|
-l |
Show only local IP |
-p |
Show only public IP |
-j |
JSON output |
-h |
Display help |
showipExample output:
Public IPv4 : 13.107.213.60
Local IPv4 : 192.168.1.24
showip -pExample:
Public IPv4 : 13.107.213.60
showip -lExample:
Local IPv4 : 192.168.1.24
showip -jExample:
{
"public_ipv4": "13.107.213.60",
"local_ipv4": "192.168.1.24"
}This is useful for:
- shell scripting
- monitoring tools
- automation pipelines
Public IPv4 : 13.107.213.60
Local IPv4 : 192.168.1.24
{
"public_ipv4": "13.107.213.60",
"local_ipv4": "192.168.1.24"
}ShowIP queries several IP detection services sequentially:
- https://icanhazip.com
- https://api.ipify.org
- https://whatismyip.akamai.com
- https://checkip.amazonaws.com
- https://ipinfo.io/ip
If one service fails or times out, the script automatically falls back to the next provider.
Instead of parsing raw ifconfig output (which is unreliable across platforms), ShowIP determines the active interface using routing information.
Uses:
ip route get <target>
Uses:
route -n get <target>
ifconfig
This routing-based detection is more reliable and works properly inside:
- Virtual Machines
- Containers
- NAT environments
ShowIP is designed to be fully portable across Unix-like systems.
Supported platforms:
- Linux
- FreeBSD
- OpenBSD
- NetBSD
- macOS
The script is written using POSIX shell, avoiding Bash-specific features.
ShowIP automatically detects one of the following tools:
| Tool | Purpose |
|---|---|
| curl | HTTP requests |
| wget | HTTP requests |
| fetch | HTTP requests (BSD systems) |
Only one of these tools is required.
- Only trusted public IP detection services are used.
- HTTP requests are performed with timeouts to avoid hanging processes.
- Output is validated to ensure valid IPv4 addresses.
- No sensitive information is stored or transmitted.
Contributions are welcome.
You can contribute by:
- reporting bugs
- suggesting improvements
- submitting pull requests
- improving documentation
Please open an Issue before submitting major changes.
This project is licensed under the BSD 2-Clause License.
See the LICENSE file for details.
Koray Üstündağ
If you find this project useful, consider:
⭐ Starring the repository
🐛 Reporting issues
🔧 Contributing improvements