rajeevs1992

AutoUpdateIP

Aug 24th, 2011
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. #Author Rajeev S
  2. #Date   24 Aug 2011
  3. #Program to update IP address with no-ip
  4. import os                       #for system and popen
  5. import urllib                   #for urlopen
  6. t=os.system("ifconfig ppp0")            #checking status of the system;wheteher online or not
  7. os.system("clear")
  8. if t==256:                  #exit if offline
  9.     print "You are not connected to the internet!Connect and restart terminal to link website!"
  10.     exit()
  11. else:                       #else read output of ifconfig ppp0
  12.     ifconfig_ppp0=os.popen("ifconfig ppp0")
  13. ifconfig_ppp0=ifconfig_ppp0.read().split()
  14. for i in ifconfig_ppp0:             #extract IP address (string that starts with addr)
  15.     if i.startswith('addr'):
  16.         ip=i[5:]
  17.         break
  18. url="http://username:[email protected]/nic/update? hostname=mytest.testdomain.com&myip="+ip
  19. handle=urllib.urlopen(url).read()       #fetch url
  20. if handle.startswith("good") or handle.startswith("nochg"):
  21.     print "\t\tIP updated!Website is now on air!!!"
Advertisement
Add Comment
Please, Sign In to add comment