Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- ##
- # This script is to automate HTTP login
- ##
- import httplib
- import urllib
- from BeautifulSoup import BeautifulSoup
- from gi.repository import Notify
- ## CONSTANT DEFINITION ##
- USERNAME = ''
- PASSWORD = ''
- FORCEIP = ''
- INPUT_ID = 'submit'
- URL = ''
- TITLE_SUCCESS = ''
- ###
- DEBUG = False
- ##########################
- params = urllib.urlencode({'input-id' : INPUT_ID,
- 'username' : USERNAME,
- 'password' : PASSWORD,
- 'forceip' : FORCEIP});
- headers = {"Content-type": "application/x-www-form-urlencoded",
- "Accept": "text/plain"}
- httpCon = httplib.HTTPConnection(URL)
- Notify.init("httpLogon")
- httpCon.request("POST", "/cgi-bin/login", params, headers)
- response = httpCon.getresponse()
- content = response.read()
- title = BeautifulSoup(content)
- if DEBUG:
- print content
- print
- print title.title.string
- if title.title.string == TITLE_SUCCESS:
- notification = Notify.Notification.new("Logon Successful",
- "Logon to the network successful","dialog-information")
- notification.show()
- else:
- error = title.findAll("div", {"class" : "error"})[0]
- error = str(error)[19:-6]
- if DEBUG:
- print error
- notification = Notify.Notification.new("Logon Error",
- "Could not automatically log on to the network - " + error,"dialog-error")
- notification.show()
Advertisement
Add Comment
Please, Sign In to add comment