mirror of
https://github.com/smxi/inxi.git
synced 2025-02-23 21:42:18 +00:00
Improve IPv6 handling to cope with multiple addresses.
Link-local addresses and privacy addresses are filtered out.
This commit is contained in:
parent
c498f92fcf
commit
cbda5b3273
24
inxi
24
inxi
|
@ -8119,6 +8119,7 @@ get_networking_local_ip_data()
|
|||
aInterfaces[interface]++
|
||||
|
||||
while (getline && !/^$/ ) {
|
||||
addIpV6 = ""
|
||||
if ( ipTool == "ifconfig" ) {
|
||||
if (/inet addr:/) {
|
||||
ifIp = gensub( /addr:([0-9\.]+)/, "\\1", "g", $2 )
|
||||
|
@ -8127,7 +8128,7 @@ get_networking_local_ip_data()
|
|||
}
|
||||
}
|
||||
if (/inet6 addr:/) {
|
||||
ifIpV6 = $3
|
||||
addIpV6 = $3
|
||||
}
|
||||
if ( bsdType == "bsd" ) {
|
||||
if ( $1 == "inet" ) {
|
||||
|
@ -8138,7 +8139,7 @@ get_networking_local_ip_data()
|
|||
}
|
||||
if ( $0 ~ /inet6.*%/ ) {
|
||||
sub(/%.*/,"",$2)
|
||||
ifIpV6 = $2
|
||||
addIpV6 = $2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8146,15 +8147,24 @@ get_networking_local_ip_data()
|
|||
if ( $1 == "inet" ) {
|
||||
ifIp = $2
|
||||
}
|
||||
if ( $1 == "inet6" ) {
|
||||
ifIpV6 = $2
|
||||
if ( $1 == "inet6" && $0 !~ / temporary/) { # filter out IPv6 privacy addresses
|
||||
addIpV6 = $2
|
||||
}
|
||||
}
|
||||
|
||||
if ( addIpV6 != "" && addIpV6 !~ /^fe80:/ ) { # filter out IPv6 link-local
|
||||
if ( ifIpV6 == "" ) {
|
||||
ifIpV6 = addIpV6
|
||||
}
|
||||
else {
|
||||
ifIpV6 = ifIpV6 "," addIpV6
|
||||
}
|
||||
}
|
||||
}
|
||||
# slice off the digits that are sometimes tacked to the end of the address,
|
||||
# like: /64 or /24
|
||||
sub(/\/[0-9]+/, "", ifIp)
|
||||
sub(/\/[0-9]+/, "", ifIpV6)
|
||||
gsub(/\/[0-9]+/, "", ifIpV6)
|
||||
ipAddresses[interface] = ifIp "," ifMask "," ifIpV6
|
||||
}
|
||||
END {
|
||||
|
@ -13515,6 +13525,7 @@ print_network_advanced_data()
|
|||
print_networking_ip_data()
|
||||
{
|
||||
eval $LOGFS
|
||||
# $ip should be IPv4
|
||||
local ip=$( get_networking_wan_ip_data )
|
||||
local wan_ip_data='' a_interfaces_working='' interfaces='' i=0
|
||||
local if_id='' if_ip='' if_ipv6='' if_ipv6_string='' full_string='' if_string=''
|
||||
|
@ -13556,7 +13567,8 @@ print_networking_ip_data()
|
|||
if [[ $B_OUTPUT_FILTER == 'true' ]];then
|
||||
if_ipv6=$FILTER_STRING
|
||||
else
|
||||
if_ipv6=${a_interfaces_working[3]}
|
||||
# may be more than one address here; get them all as one string
|
||||
if_ipv6=${a_interfaces_working[@]:3}
|
||||
fi
|
||||
fi
|
||||
if_ipv6_string=" ${C1}ip-v6$SEP3${C2} $if_ipv6"
|
||||
|
|
Loading…
Reference in a new issue