mirror of
https://github.com/SinTan1729/random.git
synced 2024-12-25 20:58:37 -06:00
fix: Handle missing interfaces properly
This commit is contained in:
parent
fd0492a1d1
commit
0010b50be7
1 changed files with 2 additions and 2 deletions
4
getip.sh
4
getip.sh
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
echo 'ipv4:'
|
echo 'ipv4:'
|
||||||
for i in eth0 eno1 wlan0; do
|
for i in eth0 eno1 wlan0; do
|
||||||
$(ip -4 addr | grep -q $i) || continue
|
$(ip -4 addr | grep -q " $i:") || continue
|
||||||
addr="$(ip -4 addr show dev $i | grep -oP '(?<=inet\s)\d+(\.\d+){3}')"
|
addr="$(ip -4 addr show dev $i | grep -oP '(?<=inet\s)\d+(\.\d+){3}')"
|
||||||
[ -z "$addr" ] || echo -e "\t$i: \t\t$addr"
|
[ -z "$addr" ] || echo -e "\t$i: \t\t$addr"
|
||||||
done
|
done
|
||||||
|
@ -15,7 +15,7 @@ echo -e "\texternal: \t${addr:-n/a}"
|
||||||
|
|
||||||
echo 'ipv6:'
|
echo 'ipv6:'
|
||||||
for i in eth0 eno1 wlan0; do
|
for i in eth0 eno1 wlan0; do
|
||||||
$(ip -6 addr | grep -q $i) || continue
|
$(ip -6 addr | grep -q " $i:") || continue
|
||||||
addr="$(ip -6 addr show dev $i | grep -oP '(?<=inet6\s)\w+(\:{1,2}\w+){4}(?=.+link)')"
|
addr="$(ip -6 addr show dev $i | grep -oP '(?<=inet6\s)\w+(\:{1,2}\w+){4}(?=.+link)')"
|
||||||
[ -z "$addr" ] || echo -e "\t$i: \t\t$addr"
|
[ -z "$addr" ] || echo -e "\t$i: \t\t$addr"
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in a new issue