imlach

Auto HTTP login

Jul 21st, 2013
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. #!/usr/bin/python
  2. ##
  3. # This script is to automate HTTP login
  4. ##
  5.  
  6. import httplib
  7. import urllib
  8. from BeautifulSoup import BeautifulSoup
  9. from gi.repository import Notify
  10.  
  11. ## CONSTANT DEFINITION ##
  12. USERNAME = ''
  13. PASSWORD = ''
  14. FORCEIP = ''
  15. INPUT_ID = 'submit'
  16. URL = ''
  17. TITLE_SUCCESS = ''
  18. ###
  19. DEBUG = False
  20. ##########################
  21.  
  22.  
  23. params = urllib.urlencode({'input-id' : INPUT_ID,
  24. 'username' : USERNAME,
  25. 'password' : PASSWORD,
  26. 'forceip' : FORCEIP});
  27. headers = {"Content-type": "application/x-www-form-urlencoded",
  28. "Accept": "text/plain"}
  29. httpCon = httplib.HTTPConnection(URL)
  30. Notify.init("httpLogon")
  31.  
  32.  
  33.  
  34. httpCon.request("POST", "/cgi-bin/login", params, headers)
  35. response = httpCon.getresponse()
  36. content = response.read()
  37. title = BeautifulSoup(content)
  38.  
  39.  
  40. if DEBUG:
  41. print content
  42. print
  43. print title.title.string
  44.  
  45. if title.title.string == TITLE_SUCCESS:
  46. notification = Notify.Notification.new("Logon Successful",
  47. "Logon to the network successful","dialog-information")
  48. notification.show()
  49. else:
  50. error = title.findAll("div", {"class" : "error"})[0]
  51. error = str(error)[19:-6]
  52.  
  53. if DEBUG:
  54. print error
  55.  
  56. notification = Notify.Notification.new("Logon Error",
  57. "Could not automatically log on to the network - " + error,"dialog-error")
  58. notification.show()
Advertisement
Add Comment
Please, Sign In to add comment