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: xone on Nov 03, '04 06:52:10PM
Hi, Here is my version of the infamous send me my ip address script. It utilises the
extract_ip(this_text)
function and shell script call to get the ip address set out in the hint above. However it is slighty neater in that it is built to be attached to a Mail rule and has no hardcoded email address.

using terms from application "Mail"
	on perform mail action with messages theMessages for rule theRule
		set response to do shell script "/usr/bin/curl http://checkip.dyndns.org/"
		set ip_address to extract_ip(response)
		tell application "Mail"
			repeat with eachMessage in theMessages
				set theSubject to subject of eachMessage
				try
					set replyMessage to reply eachMessage without opening window
					set the subject of replyMessage to ip_address
					send replyMessage
				end try
			end repeat
		end tell
	end perform mail action with messages
end using terms from
If you just create a rule (subject = wanip for example) in Mail that runs this script it will reply with your WAN IP as the subject. However, Mail does seem to be a bit flaky sometimes when running rules...or is it just me :) Tom

[ Reply to This | # ]
Short, sweet, and flexible?
Authored by: DesignX on Apr 27, '05 04:27:53PM

Since I was looking to do this myself, I'm happy to see someone else has done all the work!
Here is a combination of all the (best? most elegant??) shortest! code and seemingly most flexible in these threads. (Who am I to say? I don't know my elbow from the teakettle with shell scripts and I write AppleScript like I speak Chinese.) But this works from anywhere to anywhere (flexible) and it is short.
A combination of obscure requirements in the Mail rule, a unique script name, and/or (probably better) encrypted e-mail would keep it secure.
It is a combination of code from xone, zendrew, and whoever's shoulders they're standing on.
Comments? Improvements?

Complete and ready to run:
[code]
using terms from application "Mail"
on perform mail action with messages theMessages for rule Name_of_your_mail_rule_here
set ip_address to (do shell script "curl -f http://checkip.dyndns.org | awk '{print substr($6,1,length($6)-15)}'")
tell application "Mail"
repeat with eachMessage in theMessages
set theSubject to subject of eachMessage
try
set replyMessage to reply eachMessage without opening window
set the subject of replyMessage to ip_address
send replyMessage
end try
end repeat
end tell
end perform mail action with messages
end using terms from
[/code]


---
DesignX



[ Reply to This | # ]