网络资讯

DNSPOD API 域名的动态IP的更新脚本

2020-02-18 18:39:14   来源:   点击:
  Centos 5.5默认安装的Python版本是2.4。要升级到2.7或者其他版本需要下载源码包自己编译安装
 
 
  tar jfvx Python-2.7.tar.bz2
 
  ./configure
 
  make all
 
  make install
 
  make clean
 
  make distclean
 
  查看安装的版本信息
 
  /usr/local/bin/python2.7 -V
 
  Python 2.7 (r27:82500, Nov 2 2010, 19:25:22)[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
 
  看来新装的版本生效了,做个软连接应该就OK。
 
  mv /usr/bin/python /usr/bin/python-bak
 
  ln -s /usr/local/bin/python3.0 /usr/bin/python
 
  IP修改器升级安装好以后yum会无法使用,因为yum使用的是2.4版本的,所以要修改yum的配置文件以便能够识别2.4版本下的python
 
  vim /usr/bin/yum
 
  将文件头部的
 
  #!/usr/bin/python
 
  改成
 
  #!/usr/bin/python2.4
 
  就可以继续使用yum了
 
  DNSPOD API 域名的动态IP的更新脚本
 
  #!/usr/bin/env python
 
  #-*- coding:utf-8 -*-
 
  import httplib, urllib
 
  import socket
 
  import time
 
  params = dict(
 
  login_email="xxx@qq.com", # replace with your email
 
  login_password="xxxx", # replace with your password
 
  format="json",
 
  domain_id=776050, # replace with your domain_od, can get it by API Domain.List
 
  record_id=8073592, # replace with your record_id, can get it by API Record.List
 
  sub_domain="www", # replace with your sub_domain
 
  record_line="默认",
 
  )
 
  current_ip = None
 
  def ddns(ip):
 
  params.update(dict(value=ip))
 
  headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/json"}
 
  conn = httplib.HTTPSConnection("dnsapi.cn")
 
  conn.request("POST", "/Record.Ddns", urllib.urlencode(params), headers)
 
  response = conn.getresponse()
 
  print response.status, response.reason
 
  data = response.read()
 
  print data
 
  conn.close()
 
  return response.status == 200
 
  def getip():
 
  sock = socket.create_connection(('ns1.dnspod.net', 6666))
 
  ip = sock.recv(16)
 
  sock.close()
 
  return ip
 
  if __name__ == '__main__':
 
  while True:
 
  try:
 
  ip = getip()
 
  print ip
 
  if current_ip != ip:
 
  if ddns(ip):
 
  current_ip = ip
 
  except Exception, e:
 
  print e
 
  pass
 
  time.sleep(300)
 
  替换上你的Email,密码,域名ID,记录ID等参数,就可以运行了。
 
  国内ip代理会在后台一直运行,每隔300秒检查一遍IP,如果修改了就更新IP。
 
  获得domain_id可以用curl
 
 
  获得record_id类似
 

上一篇:动态IP静态IP——动态主机配置协议
下一篇:cisco的ip sla 实例应用--端到端的可用性动态监测

关闭
18076763811
动态IP
QQ: 944155117