Advertisement
Guest User

feedback

a guest
Nov 3rd, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.05 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ################################################################################
  4.  
  5. #Functions
  6.  
  7. function info {
  8.   echo "Usage: [-h] [-c #] [directory]"
  9. }
  10.  
  11. function guide {
  12.     echo "1- eth0, 2 - lo, 3 - Default Gateway"
  13. }
  14. function error-message {
  15.  echo "An error has occured!" >&1
  16. }
  17.  
  18. function which {
  19.    
  20. while [ "$whatint" = 0 ]; do
  21.    
  22.     read -p "What interface would you like to look at? " input1
  23.        
  24.         whatint=input1
  25.        
  26.         #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.
  27.         if [ "$whatint" = 1 ]; then
  28.             echo "Interface ${intname[0]} has address ${iparray[0]}"
  29.             exit 1
  30.         fi
  31.        
  32.         if [[ "$whatint" = 2 ]]; then
  33.             echo "Interface ${intname[1]} has address ${iparray[1]}"
  34.             exit 1
  35.         fi
  36.        
  37.         if [ $whatint = 3 ]; then
  38.             gateway=`route -n|grep '^0.0.0.0 '|awk '{print $2}'`
  39.  
  40.             echo "Default gateway is $gateway"
  41.         fi
  42. done
  43. }
  44.  
  45. ################################################################################
  46.  
  47. #Variables / Declarations
  48.  
  49. declare -i whatint
  50.  
  51. #declare interface array
  52. declare -a iparray
  53.  
  54. defaultroute="false"
  55. whatint=0
  56.  
  57. ################################################################################
  58.  
  59. #Commence while loop.
  60.  
  61. while [ $# -gt 0 ]; do
  62.     case "$1" in
  63.     -h )
  64.         info
  65.         exit 0
  66.         ;;
  67.    -r )
  68.    defaultroute="true"
  69.     ;;
  70.     * )
  71.         info
  72.         error-message "Argument '$1' not recognized"
  73.         exit 2
  74.         ;;
  75.     esac
  76.     shift
  77. done
  78.  
  79. ################################################################################
  80.  
  81. #Main
  82.  
  83. intname=(`ifconfig |grep '^[a-zA-Z]'|awk '{print $1}'`)
  84.  
  85. iparray[0]=`ifconfig ${intname[0]} | grep 'inet addr' | sed -e 's/  *inet addr://' | sed -e 's/ .*//'`
  86. iparray[1]=`ifconfig ${intname[1]} | grep 'inet addr' | sed -e 's/  *inet addr://' | sed -e 's/ .*//'`
  87.  
  88. guide
  89. which
  90.  
  91. ################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement