Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to parse raspberry pie plus python3 script to automatically report ip to Wanwang domain name

Shulou Source: shulou.com Published: 2022-06-01 22:59:42 11月16日 Update

In this issue, the editor will bring you about how to parse the raspberry pie plus python3 script to automatically report the ip to the Wanwang domain name. The article is rich and analyzed and described from a professional point of view. I hope you can get something after reading this article.

Dependence:

Raspberry pie 3b

Wanwang domain name (you need to apply for APIkey)

Python3 module:

Requests

Aliyun-python-sdk-core-v3

Aliyun-python-sdk-alidns

The script is as follows:

Import requestsimport jsonfrom aliyunsdkcore.client import AcsClientfrom aliyunsdkcore.acs_exception.exceptions import ClientExceptionfrom aliyunsdkcore.acs_exception.exceptions import ServerExceptionfrom aliyunsdkalidns.request.v20150109 import UpdateDomainRecordRequest, DescribeDomainRecordInfoRequestDOMAIN ='* .com'RID = 'rid'client = AcsClient ("appkey", "appsecret") of the domain name "cn-hangzhou") def ip (): # self-written get source IP service r = requests.get ('http://*.*.com/get/ip') if r.status_code = = 200: return r.text else: return Nonedef update_record (cip) Old): update_pi (cip) req = UpdateDomainRecordRequest.UpdateDomainRecordRequest () req.set_RecordId (RID) req.set_RR (old ['RR']) req.set_Type (old [' Type']) req.set_Value (cip) resp = client.do_action_with_exception (req) print (resp) return Truedef update_pi (cip): postdata = {'ip': ip} # write it yourself The web service for recording IP changes r = requests.post ('http://*.*.com/pi/ip', Data=postdata) return r.text = = 'ok'def connect_dns (): cip = ip () if not cip: return False req = DescribeDomainRecordInfoRequest.DescribeDomainRecordInfoRequest () req.set_RecordId (RID) resp = client.do_action_with_exception (req) .decode (' utf-8') old = json.loads (resp) if cip = old ['Value']: return True else: return update_record (cip) Old) if _ _ name__ = ='_ main__': connect_dns ()

It is then placed in crontab and executed every half hour to automatically detect and update.

The above is how to parse the raspberry pie plus python3 script to automatically report the ip to the Wanwang domain name. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Tags: Domain names raspberries scripts Wanwang content analysis services professional small and medium rich in content hours that is articles more modules knowledge articles industries perspectives information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Shulou Information Huawei Apple Docker