From cdb03510b49132e3b75690414e68c7a58d6440cd Mon Sep 17 00:00:00 2001 From: inxi-svn Date: Mon, 16 Apr 2012 20:29:13 +0000 Subject: [PATCH] adding in validation since user set ip addresses can be wrong. It's always something, sigh... --- inxi | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/inxi b/inxi index 3d01876..c758ca1 100755 --- a/inxi +++ b/inxi @@ -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"