Last active
June 16, 2024 19:50
-
-
Save bmatthewshea/ec18b2198c49e2b0422717de5ab1c9c8 to your computer and use it in GitHub Desktop.
Show public IP and other info from simple bash script or alias
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
printf "Gateway:\n"; route | grep "^default" | cut -d " " -f 10 | |
# captures ipv4 loopback/lo and primary lan interface, normally - adjust as needed: | |
printf "Private:\n"; ip -4 -o ad | grep "brd "| cut -d " " -f 7 | |
# You do not need dig/nslookup for this to work (no dnsutils packages needed): | |
printf "Public:\n"; host -4 -t a myip.opendns.com resolver1.opendns.com | grep "myip.opendns.com has"| cut -d " " -f 4 | |
# Instructions: | |
# Put this file in your path. (It does not need the ".bash" file extension.) | |
# Set permissions (example): `chmod 755 ~/scripts/myip` | |
# Run it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Gateway: | |
192.168.1.1 | |
Private: | |
192.168.1.101/24 | |
Public: | |
199.199.199.199 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instructions:
Copy the script to somewhere in your path and make it executable.
Then simply run it by typing 'myip' on the command line from any directory.