Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #============================================================
- #
- # FILE: hostconf
- #
- # USAGE: ./hostconf
- #
- # DESCRIPTION: Formatted 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.10
- # CREATED: 10/27/11 01:42:08 PST
- # REVISION: ---
- #============================================================
- # Set variable values needed by script
- SCRIPT_NAME=$0
- INTERFACES=/tmp/interfaces.lst
- # Define the function root_check
- function root_check () {
- if [[ $EUID -ne 0 ]]; then
- echo "This script must be run as root" 1>&2
- exit 1
- fi
- }
- # Define the function usage
- function usage () {
- cat <<EOF
- GNU HostConf 1.10, a non-interactive host configuration tool.
- Usage: $0 [OPTION]...<ARGUMENT>...
- Startup:
- -h, --help
- -v, --version
- -s, --show
- Logging and Output:
- -o, --output
- -q, --quiet
- Interface:
- -i, --interface
- -a, --addr
- -m, --mask
- -r, --reset
- Host and Domain:
- -n, --name
- -d, --domain
- -f, --hostname
- EOF
- exit 0
- }
- # Define the function version
- function version () {
- cat <<EOF
- #============================================================
- #
- # FILE: hostconf
- #
- # USAGE: ./hostconf
- #
- # DESCRIPTION: Formatted 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.10
- # CREATED: 10/27/11 01:42:08 PST
- # REVISION: ---
- #============================================================
- EOF
- exit 0
- }
- # Define the function int_list
- function int_list () {
- # Delete existing 'interfaces.lst' file
- if [ -f ${INTERFACES} ]; then
- rm ${INTERFACES}
- fi
- # Generate 'interface.lst' file
- 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
- }
- # Define the function show_all
- function show_all () {
- # Username
- USER=$(whoami)
- # Hostname
- HOSTNAME=$(hostname)
- # UNIX/Linux Distribution
- DIST=$(cat /etc/*-release | grep 'DISTRIB_ID' | sed 's/DISTRIB\_ID\=//g')
- # UNIX/Linux Version
- VER=$(cat /etc/*-release | grep 'DISTRIB_RELEASE' | sed 's/DISTRIB\_RELEASE\=//g')
- # UNIX/Linux Base
- BASE=$(cat /etc/*-release | grep 'DISTRIB_CODENAME' | sed 's/DISTRIB\_CODENAME\=//g')
- # UNIX/Linux Kernel Version
- KERNEL=$(uname -r)
- # Begin Information Display
- echo Username : ${USER}
- echo
- echo Hostname : ${HOSTNAME}
- echo
- echo Distribution : ${DIST}
- echo
- echo Version : ${VER}
- echo
- echo Base Derivative : ${BASE}
- echo
- echo Kernel : ${KERNEL}
- echo
- for i in `cat /tmp/interfaces`; do
- INT_VAR=${INT_VAR}|${i}
- done
- ACTIVE=$(echo Active Interfaces${INT_VAR} | sed 's/faces\|/faces\ \:\ /g' | sed 's/[\]/\ \|\ /g')
- echo ${ACTIVE}
- echo
- for i in `cat /tmp/interfaces`; do
- INT_VAR=${i}
- # Enumerate the interface configuration and set variables
- #
- # Connection Media
- MEDIA=$(ifconfig ${INT_VAR} | grep -E --only-matching '(encap\:[A-Za-z]+)' | sed 's/encap[:]//g')
- # Inet Address
- INET=$(ifconfig ${INT_VAR} | grep -E --only-matching '(addr\:)([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)' | sed 's/addr[:]//g')
- # MAC Address
- 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])')
- # Subnet Mask
- MASK=$(ifconfig ${INT_VAR} | grep -E --only-matching '(Mask\:)([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)' | sed 's/Mask[:]//g')
- echo Interface : ${INT_VAR}
- echo
- echo Connection Media : $MEDIA
- echo
- echo IPv4 : $INET
- echo
- echo Netmask : $MASK
- echo
- echo MAC Address : $MAC
- echo
- done
- }
Advertisement
Add Comment
Please, Sign In to add comment