#!/usr/bin/env pythonimport reimport osimport timeimport randomip_current = ' while True: Myip = Re.findall (R ' \d+\.\ D+\.\d+\.\d+ ', Os.popen (' Curl-s http://ddns.oray.com/checkip '). Read ()) print time.strftime ("%y-%m-%d%h:%m:%s" print ' current public IP is ', Myip if Myip and Myip! = ip_current: print ' current public IP have changed '
ip_current = Myip webinfo = Os.popen (' Curl-s/HTTP Username: password @ddns.oray.com/ph/update?hostname= domain name &myip= '). Read () print ' Commit info: ', webinfo if ' good ' in Webinfo: " print ' result:commit ok ' elif ' nochg ' in web Info: print ' result:no change ' else: print ' result:commit failure ' else: print ' current Public IP have not changed ' print '---' time.sleep (Random.randint (300,600))
Last edit boot entry file/etc/rc.local, add path:/home/shenwenkai/activeip.py
Peanut shell dynamic IP domain name resolution Python Auto-submit public IP