-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnetinfo
More file actions
executable file
·116 lines (86 loc) · 4.17 KB
/
netinfo
File metadata and controls
executable file
·116 lines (86 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
#########################################################################
# NetInfo - Display network configuration information #
# Copyright (C) 2015 Paul A. Hinchberger III #
#########################################################################
# This program is free software: you can redistribute it and/ #
# or modify it under the terms of the GNU GPLv3 as published #
# by the Free Software Foundation. #
# #
# This program is distributed in the hope that it will be #
# useful, but WITHOUT ANY WARRANTY; without even the implied #
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR #
# PURPOSE. See the GNU GPLv3 for more details. #
# #
# See <http://www.gnu.org/licenses/> for details. #
#########################################################################
OSBFCT=false
while getopts "o" OPT; do
case "${OPT}" in
o) OBSFCT=true
esac
done
shift $((OPTIND-1))
NIFACE=( $(\ls -1 /sys/class/net | grep -v lo | sort -V | tr '\n' ' ') )
! type ethtool &> /dev/null && ! type mii-tool &> /dev/null && \
echo "Could not find ethtool nor mii-tool. Link speeds will be unavailable."
printf '=%.0s' {1..79}; echo ''
NAMING="Using "
[ -e /etc/udev/rules.d/80-net-setup-link.rules ] && NAMING+="Kernel" || NAMING+="Predictable"
NAMING+=" Network Interface Names. "
LOOKUP="$(dig +short ${HOSTNAME})"
[ ${OBSFCT} ] && [ -n "${LOOKUP}" ] && LOOKUP="${LOOKUP%.*.*}.X.X"
if [ -n "${LOOKUP}" ]; then
LURSLT="DNS for ${HOSTNAME} is ${LOOKUP}"
else
LURSLT="Could not look up ${HOSTNAME}."
fi
printf "%-44s %34s\n" "${NAMING}" "${LURSLT}"
printf '=%.0s' {1..79}; echo ''
echo -e '---MAC ADDRESS--- CUR-DEV UDR-DEV LSPD ASSIGNED-IP DHCP-LOOKUP NETCTL NETWRKD'
printf '=%.0s' {1..79}; echo ''
for ((i = 0 ; i < ${#NIFACE[*]} ; i++)); do
MACADD="$(cat /sys/class/net/${NIFACE[i]}/address)"
[ ${OBSFCT} ] && FMTMAC="${MACADD%:??:??:??}:XX:XX:XX" || FMTMAC="${MACADD}"
printf "%17s " "${FMTMAC}"
printf "%-7s " "${NIFACE[i]}"
UDRDEV="$(grep -i ATTR{address}==\"${MACADD}\" /etc/udev/rules.d/* 2> /dev/null | sed 's/\(.*NAME="\)\(.*\)\(".*\)/\2/g' )"
printf "%-7s " "${UDRDEV}"
if type ethtool &> /dev/null; then
printf "%4s " "$(ethtool ${NIFACE[i]} 2> /dev/null | grep Speed | sed 's/\t//g;s/\///g;s/Mbs/M/g;s/1000M/1G/g' | cut -d\ -f2)"
elif type mii-tool &> /dev/null; then
printf "%4s " "$(mii-tool ${NIFACE[i]} 2> /dev/null | sed 's/.*negotiated \([0-9]*\).*/\1M/g;s/1000M/1G/g')"
else
echo '---- '
fi
[ "$(cat /sys/class/net/${NIFACE[i]}/carrier 2> /dev/null)" == "1" ] &&
ASSNIP="$(ip addr show ${NIFACE[i]} | sed 's/ *//g;s/\/[0-9]*//g' | grep 'inet ' | cut -d\ -f2 | sed ':a;N;$!ba;s/\n/ /g')"
[ -z "${ASSNIP}" ] && ASSNIP="00.00.00.00"
[ ${OBSFCT} ] && [ "${ASSNIP}" != "00.00.00.00" ] && ASSNIP="${ASSNIP%.*.*}.X.X"
[ $(expr length ${ASSNIP}) -gt 11 ] && FMTAIP="…${ASSNIP: -10}" || FMTAIP="${ASSNIP}"
printf "%11s " "${FMTAIP}"
[ "$(cat /sys/class/net/${NIFACE[i]}/carrier 2> /dev/null)" == "1" ] &&
DHCPIP="$(dhcpcd -t 5 -T ${NIFACE[i]} 2> /dev/null | grep 'offered\|leased\| rebinding ' | sed 's/lease of //g' | cut -d\ -f3 | sort -u)"
[ -z "${DHCPIP}" ] && DHCPIP="00.00.00.00"
[ ${OBSFCT} ] && [ "${DHCPIP}" != "00.00.00.00" ] && DHCPIP="${DHCPIP%.*.*}.X.X"
[ $(expr length ${DHCPIP}) -gt 11 ] && FMTDIP="…${DHCPIP: -10}" || FMTDIP="${DHCPIP}"
printf "%11s " "${FMTDIP}"
[ -n "${UDRDEV}" ] &&
[ -n "$(grep -i "^Interface=${UDRDEV}$" /etc/netctl/* 2> /dev/null | cut -d: -f1 )" ] &&
NCTLRL="${UDRDEV}"
[ -z "${NCTLRL}" ] &&
[ -n "$(grep -i "^Interface=${NIFACE[i]}$" /etc/netctl/* 2> /dev/null | cut -d: -f1 )" ] &&
NCTLRL="${NIFACE[i]}"
[ -z "${NCTLRL}" ] && NCTLRL="No"
printf "%-7s " "${NCTLRL}"
[ -n "${UDRDEV}" ] &&
[ -n "$(grep -i "^Name=${UDRDEV}$" /etc/systemd/network/* 2> /dev/null | cut -d: -f1 )" ] &&
NWKDRL="${UDRDEV}"
[ -z "${NWKDRL}" ] &&
[ -n "$(grep -i "^Name=${NIFACE[i]}$" /etc/systemd/network/* 2> /dev/null | cut -d: -f1 )" ] &&
NWKDRL="${NIFACE[i]}"
[ -z "${NWKDRL}" ] && NWKDRL="No"
printf "%-7s\n" "${NWKDRL}"
unset MACADD FMTMAC UDRDEV ASSNIP FMTAIP DHCPIP FMTDIP NCTLRL NWKDRL
done
printf '=%.0s' {1..79}; echo ''