Q: Apart from using a DNS Service, is there a way of getting an Xserve to notify an administrator of a change of external IP address? ... Apart from using a DNS Service, is there a way of getting an Xserve to notify an administrator of a change of external IP address? more
-
All replies
-
Helpful answers
-
by Strontium90,★HelpfulJan 14, 2014 7:16 AM in response to Akela_Kamba
Strontium90
Jan 14, 2014 7:16 AM
in response to Akela_Kamba
Level 5 (4,087 points)
Servers EnterpriseHow is your Xserve configured? Is it behind the LAN or is it in NAT mode?
If behind the LAN, you can use something like this:
curl -s checkip.dyndns.org
Then parse the result as that will give your your public address. Create some logic to compare against previous and then you will have a notification of change.
If in NAT, you can use a WatchedPath launchd script to watch the /Library/Preferences/Network/SystemConfiguration folder. I think that is applicable on 10.5. Thus, any network modification can be used to trigger an event.
R-
Apple Consultants Network
Apple Professional Services
Author "Mavericks Server – Foundation Services" :: Exclusively available in Apple's iBooks Store
-
Jan 19, 2014 2:25 PM in response to Strontium90by Akela_Kamba,★HelpfulStrontium90,
The curl command has worked and I have incorporated it into an applescript.
I will post the finished solution when I have fine tuned it.
Thanks
-
Jan 25, 2014 8:52 AM in response to Akela_Kambaby Akela_Kamba,Here is my finished solution using applescript.
If it is of use to anyone else please feel free to use/improve it.
global OLD_IP
global Current_IP
global IP_text
set OLD_IP to ""
set Current_IP to ""
set Test_text to ""
---on run get the current external IP address & set it as the Base IP to compare to
do shell script "curl -s checkip.dyndns.org"
set Pub_IP to result
set OLD_IP to Pub_IP as string
---show the address
display dialog "IP is: " & return & OLD_IP giving up after 2
on idle
try
set IP_Changed to false
set Current_IP to ""
---get the current external IP address
do shell script "curl -s checkip.dyndns.org"
set Pub_IP to result
set Current_IP to Pub_IP as string
if Current_IP is equal to OLD_IP then
set IP_Changed to false ---if it is the same then it hasn't changed (false)
else
set IP_Changed to true ---if it is different then it has changed (true)
end if
if IP_Changed is true then ---if there is a difference the email the change to administrator(s)
set target_string to Current_IP as string
set replacement_string_1 to "<html><head><title>Current IP Check</title></head><body>"
set replacement_string_2 to "</body></html>"
my replace_and_select(target_string, replacement_string_1, replacement_string_2) ---removes HTML coding
tell application "Mail"
set Mail_to_1 to "admin@address.co.uk"
set Mail_from to "sender@address.co.uk"
set theName to "Administrator"
set theAddress to Mail_to_1
set theSubject to "Server Public IP Address"
set theBody to IP_text
set newMessage to make new outgoing message with properties {subject:theSubject, content:theBody & return & return}
tell newMessage
set visible to true
set sender to Mail_from
make new to recipient at end of to recipients with properties {name:theName, address:theAddress}
activate
send
end tell
end tell
set OLD_IP to Current_IP ---set Base IP to the new one ready for next test
end if
end try
return 3600 ---wait one hour before repeating the test
end idle
on replace_and_select(target_string, replacement_string_1, replacement_string_2)
set this_text to target_string as string
set this_offset to the offset of the replacement_string_1 in this_text
set this_offset_2 to the offset of the replacement_string_2 in this_text
set this_offset_3 to this_offset + (length of the replacement_string_1)
if this_offset is not 0 then
set IP_text to items this_offset_3 thru (this_offset_2 - 1) of target_string as string
end if
return
end replace_and_select