|
|
2 cents re: getting the IP from the HTML
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)}'")
2 cents re: getting the IP from the HTML
Oops! That only works if your IP address is exactly 11 characters....
2 cents re: getting the IP from the HTML
... sorry, can't resist these little games....
2 cents re: getting the IP from the HTML
sweet.
2 cents re: getting the IP from the HTML
Cute, but will stop working if IPv6 is used all of a sadden, will it not?
2 cents re: getting the IP from the HTML
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!
CORRECTION!
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)}'")
|
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysNo new commentsLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.24 seconds |
|