Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '2 cents re: getting the IP from the HTML' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
2 cents re: getting the IP from the HTML
Authored by: zendrew on Nov 04, '04 12:04:31AM
I'm getting a real kick out of the the various (ingenious) solutions people have used to strip the html tags from around the IP address. Here's my variation on that same task, using awk. Like the author of this hint, I am only querying dyndns.org. I think it's simpler just to pipe to awk in this case, since the curl output is completely predictable and easily parsed:

set TheAddress to (do shell script "curl -f http://checkip.dyndns.org | awk '{print substr($6,1,11)}'")

display dialog "Your IP is : " default answer (TheAddress)




[ Reply to This | # ]
2 cents re: getting the IP from the HTML
Authored by: gblanco on Nov 04, '04 12:31:48AM

Oops! That only works if your IP address is exactly 11 characters....

Try:

curl -f http://checkip.dyndns.org | sed ' s.[A-Za-z<>/: ]..g '

:)



[ Reply to This | # ]
2 cents re: getting the IP from the HTML
Authored by: gblanco on Nov 04, '04 12:37:33AM

... sorry, can't resist these little games....

curl -f http://checkip.dyndns.org | sed 's/[^0-9.]//g'

... is even shorter.



[ Reply to This | # ]
2 cents re: getting the IP from the HTML
Authored by: zendrew on Nov 04, '04 12:39:45AM

sweet.



[ Reply to This | # ]
2 cents re: getting the IP from the HTML
Authored by: danva on Nov 04, '04 12:35:17AM

Cute, but will stop working if IPv6 is used all of a sadden, will it not?
I actually made a point of making it in AppleScript: I am using Unix for 10+ years and, you know, what's the fun in not fighting a new language :)



[ Reply to This | # ]
2 cents re: getting the IP from the HTML
Authored by: zendrew on Nov 04, '04 01:16:12AM
Aw, heck. This is maybe my third AppleScript, which I just wrote a week or so ago. And I'm a complete newb at awk––I understood that it's for parsing text, so I googled it and learned enough to write the snippets I posted here. I'm having a lot of fun learning this stuff, and I couldn't resist throwing in my little tidbit.

Anyway, I actually think your script is excellent––very well thought out, readable and adaptable. I'm totally gonna steal from it (and the idea of using multiple sites, as posted by baltwo) to make my own script more robust. Thanks!

[ Reply to This | # ]
CORRECTION!
Authored by: zendrew on Nov 04, '04 12:38:07AM
Sorry! The script I sent in my previous post will truncate many IP addresses. I inadvertently copied that snippet from my flawed first effort at this script, in which I had (half-asleep, I swear!) simply counted the 11 characters in my IP address (that day) and plugged that number into the script. Duh. I found the mistake as soon as I ran the script at work, where I had a longer IP address.

Here's the correct version:

set TheAddress to (do shell script "curl -f http://checkip.dyndns.org | awk '{print substr($6,1,length($6)-15)}'")

display dialog {"Your IP address is: ", TheAddress} as string


[ Reply to This | # ]