tankdthedruid

hostconf.sh

Nov 17th, 2011
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.51 KB | None | 0 0
  1. #!/bin/bash
  2. #============================================================
  3. #
  4. #          FILE:  hostconf
  5. #
  6. #         USAGE:  ./hostconf
  7. #
  8. #   DESCRIPTION:  Formatted network interface information for better readability. More options
  9. #                 planned to be coded in subsequent releases.
  10. #
  11. #       OPTIONS:  ---
  12. #  REQUIREMENTS:  ---
  13. #          BUGS:  ---
  14. #         NOTES:  Development of this tool is still in progress.
  15. #        AUTHOR:  tankd,
  16. #       COMPANY:  ---
  17. #       VERSION:  1.10
  18. #       CREATED:  10/27/11 01:42:08 PST
  19. #      REVISION:  ---
  20. #============================================================
  21.  
  22. # Set variable values needed by script
  23. SCRIPT_NAME=$0
  24. INTERFACES=/tmp/interfaces.lst
  25.  
  26. # Define the function root_check
  27. function root_check () {
  28. if [[ $EUID -ne 0 ]]; then
  29.    echo "This script must be run as root" 1>&2
  30.        exit 1
  31. fi
  32. }
  33.  
  34. # Define the function usage
  35. function usage () {
  36.     cat <<EOF
  37. GNU HostConf 1.10, a non-interactive host configuration tool.
  38. Usage: $0 [OPTION]...<ARGUMENT>...
  39.  
  40. Startup:
  41.     -h,    --help
  42.     -v,    --version
  43.     -s,    --show
  44.    
  45. Logging and Output:
  46.     -o,    --output
  47.     -q,    --quiet
  48.    
  49. Interface:
  50.     -i,    --interface
  51.     -a,    --addr
  52.     -m,    --mask
  53.     -r,    --reset
  54.    
  55. Host and Domain:
  56.     -n,    --name
  57.     -d,    --domain
  58.     -f,    --hostname
  59. EOF
  60.     exit 0
  61. }
  62.  
  63. # Define the function version
  64. function version () {
  65.     cat <<EOF
  66. #============================================================
  67. #
  68. #          FILE:  hostconf
  69. #
  70. #         USAGE:  ./hostconf
  71. #
  72. #   DESCRIPTION:  Formatted network interface information for better readability. More options
  73. #                 planned to be coded in subsequent releases.
  74. #
  75. #       OPTIONS:  ---
  76. #  REQUIREMENTS:  ---
  77. #          BUGS:  ---
  78. #         NOTES:  Development of this tool is still in progress.
  79. #        AUTHOR:  tankd,
  80. #       COMPANY:  ---
  81. #       VERSION:  1.10
  82. #       CREATED:  10/27/11 01:42:08 PST
  83. #      REVISION:  ---
  84. #============================================================
  85. EOF
  86.     exit 0
  87. }
  88.  
  89. # Define the function int_list
  90. function int_list () {
  91.  
  92. # Delete existing 'interfaces.lst' file
  93. if [ -f ${INTERFACES} ]; then
  94.     rm ${INTERFACES}
  95. fi
  96.  
  97. # Generate 'interface.lst' file
  98. ifconfig | grep -E --only-matching '(eth[0-9]+)' >> /tmp/interface.lst
  99. ifconfig | grep -E --only-matching '(wlan[0-9]+)' >> /tmp/interface.lst
  100. ifconfig | grep -E --only-matching '(ppp[0-9]+)' >> /tmp/interface.lst
  101. ifconfig | grep -E --only-matching '(vboxnet[0-9]+)' >> /tmp/interface.lst
  102. ifconfig | grep -E --only-matching '(vmnet[0-9]+)' >> /tmp/interface.lst
  103. ifconfig | grep -E --only-matching '(lo)' >> /tmp/interface.lst
  104. }
  105.  
  106. # Define the function show_all
  107. function show_all () {
  108.  
  109. # Username
  110. USER=$(whoami)
  111.  
  112. # Hostname
  113. HOSTNAME=$(hostname)
  114.  
  115. # UNIX/Linux Distribution
  116. DIST=$(cat /etc/*-release | grep 'DISTRIB_ID' | sed 's/DISTRIB\_ID\=//g')
  117.  
  118. # UNIX/Linux Version
  119. VER=$(cat /etc/*-release | grep 'DISTRIB_RELEASE' | sed 's/DISTRIB\_RELEASE\=//g')
  120.  
  121. # UNIX/Linux Base
  122. BASE=$(cat /etc/*-release | grep 'DISTRIB_CODENAME' | sed 's/DISTRIB\_CODENAME\=//g')
  123.  
  124. # UNIX/Linux Kernel Version
  125. KERNEL=$(uname -r)
  126.  
  127. # Begin Information Display
  128. echo Username : ${USER}
  129. echo
  130. echo Hostname : ${HOSTNAME}
  131. echo
  132. echo Distribution : ${DIST}
  133. echo
  134. echo Version : ${VER}
  135. echo
  136. echo Base Derivative : ${BASE}
  137. echo
  138. echo Kernel : ${KERNEL}
  139. echo
  140. for i in `cat /tmp/interfaces`; do
  141.     INT_VAR=${INT_VAR}|${i}
  142. done
  143. ACTIVE=$(echo Active Interfaces${INT_VAR} | sed 's/faces\|/faces\ \:\ /g' | sed 's/[\]/\ \|\ /g')
  144. echo ${ACTIVE}
  145. echo
  146. for i in `cat /tmp/interfaces`; do
  147.     INT_VAR=${i}
  148.     # Enumerate the interface configuration and set variables
  149.     #
  150.     # Connection Media
  151.     MEDIA=$(ifconfig ${INT_VAR} | grep -E --only-matching '(encap\:[A-Za-z]+)' | sed 's/encap[:]//g')
  152.    
  153.     # Inet Address
  154.     INET=$(ifconfig ${INT_VAR} | grep -E --only-matching '(addr\:)([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)' | sed 's/addr[:]//g')
  155.    
  156.     # MAC Address
  157.     MAC=$(ifconfig ${INT_VAR} | 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])')
  158.    
  159.     # Subnet Mask
  160.     MASK=$(ifconfig ${INT_VAR} | grep -E --only-matching '(Mask\:)([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)' | sed 's/Mask[:]//g')
  161.     echo Interface : ${INT_VAR}
  162.     echo
  163.     echo     Connection Media : $MEDIA
  164.     echo
  165.     echo     IPv4 : $INET
  166.     echo
  167.     echo     Netmask : $MASK
  168.     echo
  169.     echo     MAC Address : $MAC
  170.     echo
  171. done
  172. }
Advertisement
Add Comment
Please, Sign In to add comment