Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ################################################################################
- #Functions
- function info {
- echo "Usage: [-h] [-c #] [directory]"
- }
- function guide {
- echo "1- eth0, 2 - lo, 3 - Default Gateway"
- }
- function error-message {
- echo "An error has occured!" >&1
- }
- function which {
- while [ "$whatint" = 0 ]; do
- read -p "What interface would you like to look at? " input1
- whatint=input1
- #Test statements for if the value of $whatint is non-existant, has a value of 0, or ir less than 0. If any are true, do the following.
- if [ "$whatint" = 1 ]; then
- echo "Interface ${intname[0]} has address ${iparray[0]}"
- exit 1
- fi
- if [[ "$whatint" = 2 ]]; then
- echo "Interface ${intname[1]} has address ${iparray[1]}"
- exit 1
- fi
- if [ $whatint = 3 ]; then
- gateway=`route -n|grep '^0.0.0.0 '|awk '{print $2}'`
- echo "Default gateway is $gateway"
- fi
- done
- }
- ################################################################################
- #Variables / Declarations
- declare -i whatint
- #declare interface array
- declare -a iparray
- defaultroute="false"
- whatint=0
- ################################################################################
- #Commence while loop.
- while [ $# -gt 0 ]; do
- case "$1" in
- -h )
- info
- exit 0
- ;;
- -r )
- defaultroute="true"
- ;;
- * )
- info
- error-message "Argument '$1' not recognized"
- exit 2
- ;;
- esac
- shift
- done
- ################################################################################
- #Main
- intname=(`ifconfig |grep '^[a-zA-Z]'|awk '{print $1}'`)
- iparray[0]=`ifconfig ${intname[0]} | grep 'inet addr' | sed -e 's/ *inet addr://' | sed -e 's/ .*//'`
- iparray[1]=`ifconfig ${intname[1]} | grep 'inet addr' | sed -e 's/ *inet addr://' | sed -e 's/ .*//'`
- guide
- which
- ################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement