-
Notifications
You must be signed in to change notification settings - Fork 8
/
DynDNS.rb
46 lines (29 loc) · 1.11 KB
/
DynDNS.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Dynamic DNS scripts for DNSPod
# Written by Timothy
# Blog http://www.xiaozhou.net
# Create Date: 2012.4.4
# Last Update: 2012.4.19
# Define required blocks
require './DNSPodHelper'
require './Logger'
require 'daemons'
# Execute section
Daemons.run_proc("DynDNS") do
puts 'DynDNS daemon starting...'
helper = DNSPodHelper.instance
loop {
begin
publicIP = helper.GetPublicIPAddr
domains = helper.GetDomainInfo
subDomain = helper.GetSubDomain(domains[DNSPodHelper::CONFIG["your_Domain"]], DNSPodHelper::CONFIG["your_SubDomain"])
Utility::Log.info("Public IP is:#{publicIP.strip}, Sub-domain IP is:#{subDomain['value'].strip}")
if(subDomain['value'].strip != publicIP.strip)
Utility::Log.info("Public IP(#{publicIP.strip}) is different from sub-domain IP(#{subDomain['value'].strip}), need to update!")
helper.UpdateSubDomainIP(domains[DNSPodHelper::CONFIG["your_Domain"]], subDomain['id'], DNSPodHelper::CONFIG["your_SubDomain"], publicIP.strip)
end
rescue => e
Utility::Log.info(e.class.to_s() + " occurs, failed to finish the process! Will try next time!")
end
sleep(1*60*5)
}
end