使用Python控制DDNS解析
需求:
光纤入户,一台服务器(windows server 2008 r2),连接内部网络。
同时通过pppoe连接到公网,获取一公网IP,公网IP需要域名映射。
尝试:
1、通过Oray客户端,正确情况可解析,当pppoe断开再连接后,Oray客户端不会去主动解析到新获取的地址,需要重启。
2、使用DNSPOD客户端,状况与Oray客户端一致。
解决:
通过观察发现,当pppoe拨号成功后,windows产生20267事件,那么思路来了,可通过计划任务监视事件,发生后启动解析。
比较发现Oray方式较为简单,很容易通过Python(v3)实现:
from urllib.request import urlopen import re import pycurl html = urlopen('http://ddns.oray.com/checkip').read() html = html.decode('GBK') reip = re.compile(r'(?<![\.\d])(?:\d{1,3}\.){3}\d{1,3}(?![\.\d])') ip=reip.findall(html)[0] print(ip) url = 'http://username:password@ddns.oray.com/ph/update?myip=' + ip c = pycurl.Curl() c.setopt(c.URL, url) c.perform() |
上述代码通过http://ddns.oray.com/checkip获取公网IP,传递给url并解析
将脚本保存,并通过计划任务实现。
下图:监视事件
下图:执行脚本
13 条评论
cheapest buy androxal cheap genuine
online order androxal generic alternative
enclomiphene in chicago over the counter
how to buy enclomiphene purchase line
is it illegal to order rifaximin online
online order rifaximin generic switzerland
how can i order xifaxan without a perscrption
buy cheap xifaxan usa overnight delivery
buying staxyn generic is it safe
ordering staxyn purchase from canada
get avodart price london
avodart cheap no rx required canada
how to get free dutasteride samples
cheapest buy dutasteride generic brand
online pharmacy no prescription flexeril cyclobenzaprine
purchase flexeril cyclobenzaprine american express
buy cheap gabapentin price australia
buy cheap gabapentin uk london
order fildena generic buy online
cheap fildena cheap australia
cheap itraconazole buy for cheap
cheap itraconazole usa online
kamagra přes přepážku v kanadě
další den dodání kamagra bez skriptu
kamagra coût australie
achat kamagra pharmacie livrer a domicile de medicaments