Posted By

java2025 on 03/02/09


Tagged

dynamic DNS pavietnam


Versions (?)

IP update client for pavietnam


 / Published in: Python
 

  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  

You need to login to post a comment.