forked from KANIKIG/steamsv.github.io
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcheckdns.py
executable file
·61 lines (49 loc) · 1.58 KB
/
checkdns.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
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
#coding: utf-8
import commands, sys, os, json
# dnsmasq配置文件路径
path = "/etc/dnsmasq.d/unlock.conf"
# dns配置,一行一个规则对应DDNS
dnsconf = '''
{
"netflix.com":"us1.ddns.bar",
"netflix.net":"us1.ddns.bar",
"nflximg.net":"us1.ddns.bar",
"nflximg.com":"us1.ddns.bar",
"nflxvideo.net":"us1.ddns.bar",
"nflxso.net":"us1.ddns.bar",
"nflxext.com":"us1.ddns.bar"
}
'''
# 以下勿动
if os.path.exists(path):
with open(path) as unlockconf:
unlockconf = unlockconf.read().split("\n")
else:
print "check dnsmasq config path"
exit()
dnsconf = json.loads(dnsconf)
change = False
for host, dns in dnsconf.iteritems():
output = commands.getoutput("nslookup " + dns)
output = output.split("\n");
for str in output:
if "Address" in str and "#53" not in str:
str = str.replace("Address:","")
str = str.replace(" ","")
ip = str.replace("\t","")
print "nslookup: " + host + "/" + dns + "/" + ip
for index, rule in enumerate(unlockconf):
if host in rule:
if rule.split("/")[2] != ip:
unlockconf[index] = "server=/" + host + "/" + ip
print "changed: " + unlockconf[index]
change = True
if change == True:
s = "\n".join(unlockconf)
with open(path, 'w') as outfile:
outfile.write(s)
outfile.close()
output = commands.getoutput("systemctl restart dnsmasq")
if output != "":
print output