forked from NewFuture/DDNS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
executable file
·52 lines (46 loc) · 1.48 KB
/
run.py
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
46
47
48
49
50
51
52
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import dnspod
import ip
import json
import argparse
def get_config(key=None, file="config.json"):
if not hasattr(get_config, "config"):
try:
with open(file) as configfile:
get_config.config = json.load(configfile)
except:
exit('fail to load config from file: %s' % file)
if key:
return get_config.config.get(key)
else:
return get_config.config
def update():
index4=get_config('index4') or 0
if str(index4).isdigit():
ipv4 = ip.local_v4(index4)
else:
ipv4 = getattr(ip,index4+"_v4")()
print 'update ipv4 to:', ipv4
if ipv4 != None:
for domain in get_config('ipv4'):
print dnspod.change_record(domain, ipv4, 'A')
v6_domains=get_config("ipv6")
if len(v6_domains) > 0:
index6=get_config('index6')
if str(index6).isdigit():
ipv6 = ip.local_v6(index6)
else:
ipv6 = getattr(ip,index6+"_v6")()
print 'update ipv6 to:', ipv6
if ipv6 != None:
for domain in v6_domains:
print dnspod.change_record(domain, ipv6, 'AAAA')
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-c',default="config.json")
get_config(file=parser.parse_args().c)
dnspod.TOKEN = "%s,%s" % (get_config('id'), get_config('token'))
dnspod.PROXY = get_config('proxy')
ip.DEBUG = get_config('debug')
update()