Last active
November 22, 2015 21:58
-
-
Save williamcanin/ef0a4c2c4191ff3ac294 to your computer and use it in GitHub Desktop.
IP capture and public IP. (Script Shell) Linux terminal
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 | |
# | |
# Description: Simple script (shell) for view your IP and IP Public. | |
# By: William Canin <williamcanin.com> {william.costa.canin@gmail.com} | |
# | |
# Package dependencies: | |
# > net-tools | |
# > lynx | |
# Network interface card. Example: eth0, eth1, enp19s0, wlan0, wlan1, wlp7s0,... etc. | |
INET_FACE="" | |
# Form 1 for Arch Linux, CentOS, Fedora and derivatives. | |
# IP=$(ifconfig $INET_FACE | awk '/inet/ {sub(/:/," "); print $2}' | sed '2d') | |
# Form 2 for Debian, Ubuntu and derivatives. | |
#IP=$(ifconfig $INET_FACE | grep "inet end" | awk -F: '{ print $2 }' | awk '{ print $1 }') | |
# Form 3 Extra - If the above does not work out. | |
# IP=$(ifconfig $INET_FACE | awk -F: '/inet addr/{ print $2 }' | awk '{ print $1 }') | |
# Do you need a connection to the internet. | |
# PUBLIC_IP=$(lynx -dump -hiddenlinks=ignore -nolist http://checkip.dyndns.org:8245/ | awk '{ printf $4 }') | |
# Show | |
if [[ ! -z "$INET_FACE" ]]; then | |
if [[ ! -z "$IP" ]]; then | |
printf "\nYour IP: $IP\n" | |
else | |
printf "\nVariable 'IP' null or comment.\n" | |
fi | |
if [[ ! -z "$PUBLIC_IP" ]]; then | |
printf "Your IP Public: $PUBLIC_IP\n\n" | |
else | |
printf "\nVariable 'PUBLIC_IP' null or comment.\n\n" | |
fi | |
else | |
printf "\nVariable 'INET_FACE' null.\n\n" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment