...用api读取本机ip,dnspod通过接口解析本地ippython脚本

...用api读取本机ip,dnspod通过接口解析本地ippython脚本

2023年7月10日发(作者:)

linux⽤api读取本机ip,dnspod通过接⼝解析本地ippython脚本最近内⽹搭建了⼀台gitlab服务器,因为是内⽹没有公⽹ip,为了⽅便同事访问,dnspod直接解析了内⽹ip但是⽹卡使⽤的是dhcp的获取ip的,每次关机可能会导致ip变动,所以通过dnspod接⼝改写了官⽅脚本来实现⾃动解析!下⾯是我改下的脚本,你也可以把他写到计划任务⾥⾯多少分钟或⼩时执⾏⼀次!#!/usr/bin/env python2# -*- coding:utf-8 -*-import httplibimport urllibimport socketimport timeID = "秘钥⾥⾯设置获取到" # relace with yours, get it as link above show = "秘钥⾥⾯设置获取到" # relace with yours, get it as above link show you.#params = dict(login_token=("%s,%s" % (ID, Token)),format="json",domain_id=通过curl获取到, # replace with your domain_od, can get it by API cord_id=通过curl获取到, # replace with your record_id, can get it by API #curl '/' -d 'login_token=你的id,Token&format=json&domain_id=上⾯获取到的'sub_domain="dev", # replace with your sub_domainrecord_line="默认", #)current_ip = Nonedef ddns(ip):(dict(value=ip))headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/json"}conn = onnection("")t("POST", "/", ode(params), headers)response = ponse()print , data = ()print ()return == 200#获取本机ipdef getip():try:s = (_INET, _DGRAM)t(('8.8.8.8', 80))ip = kname()[0]finally:()return ipif __name__ == '__main__':while True:try:ip = getip()print ipif current_ip != ip:if ddns(ip):current_ip = ipexcept Exception as e:print (30)

发布者:admin,转转请注明出处:http://www.yc00.com/web/1688933041a185033.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信