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

Click here to return to the 'An AppleScript to obtain the WAN IP address' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An AppleScript to obtain the WAN IP address
Authored by: danva on Nov 03, '04 06:55:53PM

Sorry for the mess guys. Here comes an updated version.

set response to do shell script "/usr/bin/curl"
set ip_address to extract_ip(response)

set the Reply to display dialog "You IP address is: " & ip_address
buttons {"Send by email", "Just leave in pasteboard"}
default button "Just leave in pasteboard" giving up after 10 with icon stop

-- Leave the ip address in the Finder's pasteboard so it is accesible
tell application "Finder"
set the clipboard to ip_address
end tell

-- Send en email if requested
set mailto_addr to "EMAILADDRESS"

if button returned of Reply is "Send by email" then
send_ipget_mail_message(mailto_addr, ip_address)
end if

on send_ipget_mail_message(email_address, ip_address)
tell application "Mail"
set composedMessage to (a reference to (make new outgoing message
at the beginning of outgoing messages))
tell composedMessage
make new to recipient at beginning of to recipients
with properties {address:email_address}
set the subject to "iPGet report"
set the content to ip_address
end tell
send composedMessage
end tell
end send_ipget_mail_message

-- Function to extract ip from HTML returned by
on extract_ip(this_text)
set clean_ip to ""
set this_char to ""
repeat with this_char in this_text
set this_char to the contents of this_char
if the this_char is in {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "."} then
set the clean_ip to the clean_ip & this_char as string
end if
end repeat
return the clean_ip
end extract_ip

Thanks to everyone who tried this out

[ Reply to This | # ]