1
0
mirror of https://github.com/moshix/mvs.git synced 2026-04-25 03:54:38 +00:00

Generalized script now, easy to extend

This commit is contained in:
moshix
2023-04-16 20:22:16 +02:00
committed by GitHub
parent 7d3865c545
commit f543776b27

View File

@@ -1,57 +1,41 @@
#!/bin/bash #!/bin/bash
# Linux all IPv4 addresses parser # Macos all addresses parser
# run with ./nicparser.bash, for example in your .bash_profile
#
# Copyright 2023 by Moshix - All right reserved # Copyright 2023 by Moshix - All right reserved
# You may only execute this script but not redistribute or enhance without first including the full # You may only execute this script but not redistribute or enhance without first including the full
# script in its entirety as comment in your own changes or enhancements # script in its entirety as comment in your own changes or enhancements
# v 0.1 Humble beginnings # v 0.1 Humble beginnings
# v 0.2 Exclude non IP4 interfaces # v 0.2 Exclude non IP4 interfaces
# v 0.3 Linux usual NICs as well as Hercules tap/tun/docker stuff # v 0.3 Color!
# v 0.4 Generalized version for MacOs and Linux
# v 0.5 Nicer output
for counter in 0 1 ;
do # terminal handling globals
result=`ifconfig docker"$counter" 2>/dev/null` red=`tput setaf 1`
if grep -q "inet " <<< "$result"; then green=`tput setaf 2`
echo -n -e "NIC docker$counter:\t" yellow=`tput setaf 3`
ifconfig docker"$counter" | grep "inet " | awk '{print $2}' blue=`tput setaf 4`
fi magenta=`tput setaf 5`
done cyan=`tput setaf 6`
white=`tput setaf 7`
blink=`tput blink`
for counter in 0 1 2 3 4 5 6 160 161 162 164 rev=`tput rev`
do reset=`tput sgr0`
result=`ifconfig ens"$counter" 2>/dev/null` # echo "${red}red text ${green}green text${reset}"
if grep -q "inet " <<< "$result"; then
echo -n -e "NIC ens$counter:\t" #echo "These are your IPv4 addresses on your system"
ifconfig ens"$counter" | grep "inet " | awk '{print $2}'
fi for nictype in en utun bridge docker tap tun ens eth
done do
for counter in 0 1 2 3 4 5 6 100 101 102 103 104 160 161 162
do
result=`ifconfig $nictype$counter 2>/dev/null`
for counter in 0 1 2 3 4 5 6; if grep -q "inet " <<< "$result"; then #NIC exists...
do echo -n -e "${blue}$nictype$counter: \t${reset}"
result=`ifconfig eth"$counter" 2>/dev/null` ifconfig "$nictype$counter" | grep "inet " | awk 'BEGIN{ORS=""}{print $2}' # ORS controls new line
if grep -q "inet " <<< "$result"; then echo -e "${reset}"
echo -n -e "NIC eth$counter:\t" fi
ifconfig eth"$counter" | grep "inet " | awk '{print $2}' done
fi
done
for counter in 0 1 2 3 4 5;
do
result=`ifconfig tap"$counter" 2>/dev/null`
if grep -q "inet " <<< "$result"; then
echo -n -e "NIC tap$counter:\t"
ifconfig tap"$counter" | grep "inet " | awk '{print $2}'
fi
done
for counter in 0 1 2 3 4 ;
do
result=`ifconfig tun"$counter" 2>/dev/null`
if grep -q "inet " <<< "$result"; then
echo -n -e "NIC tun$counter:\t"
ifconfig tun"$counter" | grep "inet " | awk '{print $2}'
fi
done done