Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #============================================================
- #
- # FILE: ifchk
- #
- # USAGE: ./ifchk
- #
- # DESCRIPTION: Formated network interface information for better readability. More options
- # planned to be coded in subsequent releases.
- #
- # OPTIONS: ---
- # REQUIREMENTS: ---
- # BUGS: ---
- # NOTES: Development of this tool is still in progress.
- # AUTHOR: (tankd),
- # COMPANY: ---
- # VERSION: 1.0
- # CREATED: 10/27/11 01:42:08 PST
- # REVISION: ---
- #============================================================
- # Test for root permissions and terminate
- if [[ $EUID -ne 0 ]]; then
- echo "This script must be run as root" 1>&2
- exit 1
- fi
- # Get a list of activated interfaces
- ifconfig | grep -E --only-matching '(eth[0-9]+)' >> /tmp/interface.lst
- ifconfig | grep -E --only-matching '(wlan[0-9]+)' >> /tmp/interface.lst
- ifconfig | grep -E --only-matching '(ppp[0-9]+)' >> /tmp/interface.lst
- ifconfig | grep -E --only-matching '(vboxnet[0-9]+)' >> /tmp/interface.lst
- ifconfig | grep -E --only-matching '(vmnet[0-9]+)' >> /tmp/interface.lst
- ifconfig | grep -E --only-matching '(lo)' >> /tmp/interface.lst
- # Create variable $INT from user input
- INT=$1
- # Test for empty variable $INT and terminate
- if [ $INT = "" ]; then
- echo ERROR: No interface specified.
- exit 1
- fi
- # Test user input against generated interface list
- for i in `cat /tmp/interface.lst`; do
- if [ $i = ${INT} ]; then
- STR_CHK=True
- break
- else
- STR_CHK=False
- fi
- done
- # If user input does not match any interfaces on the list terminate
- if [ $STR_CHK = False ]; then
- echo ERROR: Unrecognized interface
- exit 1
- fi
- # Display all available interfaces
- # cat /tmp/interfaces.lst
- # Enumerate the interface configuration and set variables
- #
- # Connection Media
- MEDIA=$(ifconfig ${INT} | grep -E --only-matching '(encap\:[A-Za-z]+)' | sed 's/encap[:]//g')
- # Inet Address
- INET=$(ifconfig ${INT} | grep -E --only-matching '(addr\:)([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)' | sed 's/addr[:]//g')
- # MAC Address
- MAC=$(ifconfig ${INT} | grep -E --only-matching '([a-z0-9][a-z0-9]\:[a-z0-9][a-z0-9]\:[a-z0-9][a-z0-9]\:[a-z0-9][a-z0-9]\:[a-z0-9][a-z0-9]\:[a-z0-9][a-z0-9])')
- # Subnet Mask
- MASK=$(ifconfig ${INT} | grep -E --only-matching '(Mask\:)([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)' | sed 's/Mask[:]//g')
- # Username
- USER=$(whoami)
- # Hostname
- HOST=$(hostname)
- # Display gathered information
- echo Interface Information - ${INT}
- echo
- echo Connection Type - $MEDIA
- echo
- echo IPv4 - $INET
- echo
- echo Netmask - $MASK
- echo
- echo MAC Address - $MAC
- # External IP
- NAT=$(curl 'http://automation.whatismyip.com/n09230945.asp')
- # ARIN Search
- WHOIS=$(curl http://whois.arin.net/rest/ip/${NAT}.txt)
- # Variables established list
- #
- # $0*
- # $INT
- # $MEDIA
- # $INET
- # $MAC
- # $MASK
- # $NAT
- # $WHOIS
- # Test for Linux distro, kernel, and base
- DIST=$(cat /etc/*-release | grep 'DISTRIB_ID' | sed 's/DISTRIB\_ID\=//g')
- VER=$(cat /etc/*-release | grep 'DISTRIB_RELEASE' | sed 's/DISTRIB\_RELEASE\=//g')
- BASE=$(cat /etc/*-release | grep 'DISTRIB_CODENAME' | sed 's/DISTRIB\_CODENAME\=//g')
- KERNEL=$(uname -r)
- echo 'DISTRO=${DIST}'
- echo 'VERSION=${VER}'
- echo 'KERNEL=${KERNEL}'
- echo 'BASE=${BASE}'
Advertisement
Add Comment
Please, Sign In to add comment