Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python2.7
- __author__ = 'irenicus09'
- __email__ = 'irenicus09[at]gmail[dot]com'
- __license__ = 'BSD'
- """
- Antamedia Automatic Login Bot
- - Antamedia is a software used by some ISP's
- to auto disconnect users connected to a network after some idle time.
- Users who are disconnected from the network need to reconnect
- with required credentials in order to regain their internet connection.
- - This script aims to solve that issue by acting as a headless browser & filling in the form
- on the users behalf at regular intervals if the connection is found to be disconnected.
- - Utilizes the mechanize library in python, which may have to be installed manually.
- """
- from time import sleep
- from datetime import datetime
- import mechanize, sys
- class AutoConnectionBot(object):
- def __init__(self, sleep_time=300, usr="", pwd=""):
- self.sleep_time = sleep_time
- self.usr = usr
- self.pwd = pwd
- def setBrowser(self):
- self.br = mechanize.Browser()
- self.br.set_handle_equiv(True)
- self.br.set_handle_redirect(True)
- self.br.set_handle_referer(True)
- self.br.set_handle_robots(False)
- self.br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20110506 Firefox/4.0.1')]
- self.br.set_debug_http(False)
- def Main(self):
- while True:
- try:
- self.setBrowser()
- print '\n'
- print "*"*100
- print "[*] Performing Antamedia Connection Check at %s" % datetime.now()
- self.br.open("http://www.google.com/")
- if (self.br.title().strip() == 'Google'):
- print '[+] Already connected to Antamedia'
- print "[*] Sleeping for %d seconds." % (self.sleep_time)
- print "="*100
- self.br.close()
- sleep(self.sleep_time)
- else:
- print '[!] Attempting to connect to Antamedia'
- self.br.select_form(nr=0)
- self.br['userlogin'] = self.usr
- self.br['userpass'] = self.pwd
- self.br.submit()
- self.br.open("http://www.google.com/")
- if (self.br.title().strip() == 'Google'):
- print '[+] Already connected to Antamedia'
- print "[*] Sleeping for %d seconds." % (self.sleep_time)
- print "="*100
- self.br.close()
- sleep(self.sleep_time)
- else:
- print '[!] IP Address Conflict Detected.'
- print '[*] Retrying in %d seconds.' % (self.sleep_time)
- print "="*100
- self.br.close()
- sleep(self.sleep_time)
- except (KeyboardInterrupt):
- print '[!] Keyboard Interrupt Detected - Quitting..'
- sys.exit(0)
- except (IOError):
- print "[!] Error occured while connecting to Network."
- print "[*] Retrying in %d seconds." % (self.sleep_time)
- print "="*100
- sleep(self.sleep_time)
- except (Exception):
- print "[!] Unknown Error occured - Quitting.."
- print "="*100
- sys.exit(1)
- if __name__ == '__main__':
- Bot = AutoConnectionBot(usr="RoomNumber", pwd="SomePassword")
- Bot.Main()
Advertisement
Add Comment
Please, Sign In to add comment