IP update client for pavietnam


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #!/usr/bin/env python
  2.  
  3. import time, urllib, logging, socket, traceback
  4.  
  5. SITE_1_URL = 'vietnam1.net'
  6. SITE_1_PW = '134243242'
  7. SITE_1_URL = 'vietnam2.net'
  8. SITE_2_PW = '234236656'
  9.  
  10. UPDATE_INTERVAL = 60#1 minute
  11. ip = socket.gethostbyname('theheviet.net')
  12. logging.basicConfig(level=logging.INFO,
  13. format='%(asctime)s %(levelname)s %(message)s'
  14. ,filename='/var/log/padyn.log',filemode='a'
  15. )
  16.  
  17. def update_dns(domain,pw):
  18. f = urllib.urlopen('http://support.pavietnam.vn/padyn.php?host=@|www&ip='
  19. + ip + '&domain=' + domain + '&password=' + pw + '&ran=32834')
  20. ret = f.read()
  21. f.close()
  22. if ret != 'ok':
  23. logging.error('dns update was not successful')
  24. else:
  25. logging.info('dns update successfull: ' + domain + ' => ' + ip)
  26.  
  27. logging.info('padyn started')
  28. while 1:
  29. try:
  30. f = urllib.urlopen('http://pavietnam.vn/getip.php')
  31. my_ip = f.read()
  32. f.close()
  33. logging.debug('got public IP: ' + my_ip)
  34.  
  35. if my_ip != ip:
  36. logging.info('detect IP changed from ' + ip + ' => ' + my_ip + ', start updating dns...')
  37. ip = my_ip
  38. # update_dns(SITE_1_URL,SITE_1_PW)
  39. update_dns(SITE_2_URL,SITE_2_PW)
  40. else:
  41. logging.debug('IP does not change')
  42.  
  43. time.sleep(UPDATE_INTERVAL)
  44. except Exception:
  45. logging.error(traceback.format_exc())

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.