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


Click here to return to the '10.4: Retrieve WAN IP via script and Automator' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Retrieve WAN IP via script and Automator
Authored by: notverypc on Jun 07, '06 07:58:06AM
I wanted to do a similar thing with my home network. My solution was to use AppleScript and mail. I would email my home Mac and in return it would email me my WAN IP address. In Mail I setup a Rule that would run the following AppleScript. Fairly simple and effective.

set response to do shell script "/usr/bin/curl http://checkip.dyndns.org/"
set ip_address to extract_ip(response)
set mailto_addr to "me@my.domain.com" -- Change to your email address
send_ipget_mail_message(mailto_addr, ip_address)

on send_ipget_mail_message(email_address, ip_address)
	tell application "Mail"
		activate
		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 ip_address
			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 dydns.com
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


[ Reply to This | # ]