- #!/bin/sh
- # BEFORE: LOGIN
- ################################################################################
- #
- # interfaces.sh (display all interfaces with and without an IP address)
- #
- ################################################################################
- # Copyright (c) 2016, Manuel Strauch (manuel.strauch@outlook.com)
- # All rights reserved.
- #
- # Redistribution and use in source and binary forms, with or without
- # modification, are permitted provided that the following conditions are met:
- #
- # -Redistributions of source code must retain the above copyright notice,
- # this list of conditions and the following disclaimer.
- # -Redistributions in binary form must reproduce the above copyright notice,
- # this list of conditions and the following disclaimer in the documentation
- # and/or other materials provided with the distribution.
- #
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- # POSSIBILITY OF SUCH DAMAGE.
- ################################################################################
- ### functions
- ################################################################################
- ################################################################################
- screenoutput() {
- if [ "`echo $i | wc -m | sed -e 's/ //g'`" = "6" ]; then
- echo -e " ${blue} ${i}${normal} | ${yellow} ${j}${normal}"
- else
- if [ "`echo $i | wc -m | sed -e 's/ //g'`" = "5" ]; then
- echo -e " ${blue} ${i}${normal} | ${yellow} ${j}${normal}"
- else
- echo -e " ${blue} ${i}${normal} | ${yellow} ${j}${normal}"
- fi
- fi
- }
- ### start program
- ################################################################################
- ################################################################################
- case "$1" in
- start)
- ### needed variables
- ################################################################################
- ################################################################################
- . /opt/etc/system.var
- gateway="`/sbin/route -n get default 2>/dev/null | grep "gateway" | sed 's/ //g' | cut -f2 -d':'`"
- if [ -z "${gateway}" ]; then
- gateway="not available"
- fi
- all_interfaces="`/sbin/ifconfig | /usr/bin/egrep "^[a-z][a-z]?[a-z]?[a-z][0-9]" | \
- cut -f1 -d':'`"
- j="----====----"
- ### interfaces without a IP
- ################################################################################
- ################################################################################
- echo
- echo " ========================================="
- echo -e " ${red}NO IP ${blue}Interface ${normal} | ${yellow} IP-Address${normal}"
- echo " -----------------------------------------"
- for i in ${all_interfaces}; do
- noip="false"
- /sbin/ifconfig ${i} | /usr/bin/grep "inet" >/dev/null 2>&1 || noip="true"
- if [ "${noip}" == "true" ]; then
- screenoutput "{@}"
- fi
- done
- ### interfaces with a IPV4 address
- ################################################################################
- ################################################################################
- echo " ========================================="
- echo -e " ${red}IPV4 ${blue}Interface ${normal} | ${yellow} IP-Address${normal}"
- echo " -----------------------------------------"
- for i in ${all_interfaces}; do
- ips="`/sbin/ifconfig ${i} | /usr/bin/grep "inet " | cut -f2 -d' '`"
- for j in ${ips}; do
- screenoutput "{@}"
- done
- done
- ### interfaces with a IPV6 address
- ################################################################################
- ################################################################################
- echo " ========================================="
- echo -e " ${red}IPV6 ${blue}Interface ${normal} | ${yellow} IP-Address${normal}"
- echo " -----------------------------------------"
- for i in ${all_interfaces}; do
- ips="`/sbin/ifconfig ${i} | /usr/bin/grep "inet6" | cut -f2 -d' '`"
- for j in ${ips}; do
- screenoutput "{@}"
- done
- done
- echo " ========================================="
- echo -e " ${red} Default ${blue}Gateway ${normal} | ${yellow} ${gateway} ${normal}"
- echo " -----------------------------------------"
- echo
- ;;
- stop)
- ;;
- *)
- ### dummy to start the script at runtime without the option "start"
- ################################################################################
- ################################################################################
- $0 start
- ;;
- esac
- exit 0