adding in validation since user set ip addresses can be wrong. It's always something, sigh...

This commit is contained in:
inxi-svn 2012-04-16 20:29:13 +00:00
parent de5ccd8a1c
commit cdb03510b4

13
inxi
View file

@ -1,7 +1,7 @@
#!/bin/bash
########################################################################
#### Script Name: inxi
#### version: 1.7.32
#### version: 1.7.33
#### Date: April 16 2012
#### Patch Number: 00
########################################################################
@ -4699,13 +4699,20 @@ get_networking_wan_ip_data()
# get ip using wget redirect to stdout. This is a clean, text only IP output url,
# single line only, ending in the ip address. May have to modify this in the future
# to handle ipv4 and ipv6 addresses but should not be necessary.
ip=$( wget -q -O - $WAN_IP_URL | gawk '{
# awk has bad regex handling so checking it with grep -E instead
# ip=$( echo 2001:0db8:85a3:0000:0000:8a2e:0370:7334 | gawk --re-interval '
# ip=$( wget -q -O - $WAN_IP_URL | gawk --re-interval '
ip=$( wget -q -O - $WAN_IP_URL | gawk --re-interval '
{
#gsub("\n","",$2")
print $NF
}' )
# validate the data
if [[ -z $ip ]];then
ip='None Detected!'
elif [[ -z $( grep -Es \
'^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}|[[:alnum:]]{0,4}:[[:alnum:]]{0,4}:[[:alnum:]]{0,4}:[[:alnum:]]{0,4}:[[:alnum:]]{0,4}:[[:alnum:]]{0,4}:[[:alnum:]]{0,4}:[[:alnum:]]{0,4})$' <<< $ip ) ]];then
ip='IP Source Corrupt!'
fi
echo "$ip"
log_function_data "ip: $ip"