Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1. import base64, httplib, string, urllib2
  2.  
  3. username = "username"
  4. password = "password"
  5. domain = "home.domain.com"
  6.  
  7. def getIPFromUrl(url):
  8.     return urllib2.urlopen(url).read()
  9.  
  10. def createAuthString(username, password):
  11.     authString = base64.encodestring(username + ":" + password)
  12.     authString = string.replace(authString, "\012", "")
  13.     return authString
  14.  
  15. def sendRequest(host, authString, updateParams):
  16.     request = httplib.HTTPS(host)
  17.     request.putrequest("GET", updateParams)
  18.     request.putheader("HOST", host)
  19.     request.putheader("USER-AGENT", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)")
  20.     request.putheader("AUTHORIZATION", "Basic " + authString)
  21.     request.endheaders()
  22.     return request
  23.  
  24. def updateIP(ip, username, password, domain):
  25.     host = "www.ovh.com"
  26.     authString = createAuthString(username, password)
  27.     updateParams = "/nic/update?system=dyndns&hostname=" + domain + "&myip=" + ip
  28.     request = sendRequest(host, authString, updateParams)
  29.  
  30.     errcode, errmsg, headers = request.getreply()
  31.  
  32.     try:
  33.         response = request.getfile().read()
  34.     except:
  35.         response = "No output from request."
  36.  
  37.     print "[*]http code = " + `errcode`
  38.     print "[*]http msg  = " + errmsg
  39.     print "[*]http response = " + response
  40.  
  41. def main():
  42.     ip = getIPFromUrl("https://domain.com/ip.php")
  43.     updateIP(ip, username, password, domain)
  44.  
  45. if __name__ == "__main__":
  46.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement