Page: Previous  1, 2

techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4127
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
that would be pointless, I can trust my ip page to always be there, I can't trust any other site that could vanish at any time. I can also trust that the server is up and running and serving requests quickly.

Simplifications should achieve actual improvement in speed or whatever.

Although in inxi we adopted high code readability over brevity, the lines you posted are realy just a single line of code, wget piped to awk that prints the second item. However, I do note I should be using $NF, not $2, that way anyone can swap sources, I'll add that tweak in, make it a user assignable variable.
Back to top
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4127
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
1.7.32, added in new global, WLAN_IP_URL that can be set to any page desired.

the page MUST output only ONE Line of text, and the last string on that line MUST be the ip address.

Not the ip address then a period or whatever.

Ok, good to make this stuff flexible.

As with all the top globals, this can be set in a global inxi config file or a user config file and that will override the default.

Added: grr, I just realized, the error handling was already present in in the original page, because if the string: is: did not occur in the output, the ip would be null.

I have to watch this type of trying to please random posters, I'm going to have to add validation on the IP address now, grrr. And need to add so me comments so I don't randomly undo things that were actually very robust and simple.
Back to top
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4127
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
Since inxi is now allowing in data that could be bad or corrupted, via other ip sources, I had to add in full validation, it will check ip v4 and ipv6 and give either null data message, or corrupted data, on failure.

and that's that, 1.7.33.
Back to top
KenJackson
Status: New User - Welcome
Joined: 15 Apr 2012
Posts: 2
Location: Maryland, USA
Reply Quote
Random posters? Grrr

Actually, I understand you points. But scripting is fun, so I thought I'd share.

I have lots of stuff like this in my various and sundry scripts. I use head because if there's ever an error I'm likely to receive a multi-line error page.

:: Code ::
IP="$(curl -s http://queryip.net/ip/)"
case "$IP" in
    ""|*[!0-9.]*)
        error_exit "Invalid IP address \"$(echo $IP | head -n1)\"" ;;
esac

Back to top
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4127
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
[!0-9.]*

I found it surprisingly difficult to get a solid regex, so i finally dropped elegance and now check for the actual structure.

the above is true for: 122.12.3.4........4444444..44..4.4.

after learning that gawk has poor support for standard {1,3} type numbering of occurances, along with some other regex oddities, I settled on this test:

:: Code ::
# 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


while inelegant, it's accurate. While testing other versions I realized that string like:

your ip address is: 188.12.23.233.
would be true with a more general pattern. As would be :
1888888....12.

Once inxi has to accept random data of unknown quality, it has to do more validation, tedious, but I strive for reasonably reliable output.
Back to top
Display posts from previous:   
Page: Previous  1, 2
All times are GMT - 8 Hours