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: phillymjs on Jun 07, '06 11:03:09AM
Here's an Applescript I use to report IP address changes via a message sent through Mail.app. I save it as an application and run it regularly using a cron job.

try
set currentIP to (do shell script "curl -sS http://whatismyIP.org";)
on error
quit
end try
try
set lastknownIP to (do shell script "cat /Users/Shared/externalIP.txt")
on error
set lastknownIP to "0.0.0.0"
do shell script "echo " & currentIP & " > /Users/Shared/externalIP.txt"
end try

if currentIP is not lastknownIP then --if the IPs are not the same, then report it
set mailSubj to "New IP: " & currentIP
tell application "Mail"
set theMessage to (make new outgoing message with properties {subject:mailSubj, content:"IP address has changed.", visible:false})
tell theMessage
make new to recipient at end of to recipients with properties {name:"to recipient", address:"torecipient@company.com"}
make new cc recipient at end of cc recipients with properties {name:"cc recipient", address:"ccrecipient@company.com"}
end tell
send theMessage
end tell
do shell script "echo " & currentIP & " > /Users/Shared/externalIP.txt"
end if

---
--
Ohhh, WHY did I register with Insta-Trace???

[ Reply to This | # ]