irenicus09

Antamedia Autologin Bot

Mar 30th, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.56 KB | None | 0 0
  1. #!/usr/bin/env python2.7
  2.  
  3.  
  4. __author__    = 'irenicus09'
  5. __email__     = 'irenicus09[at]gmail[dot]com'
  6. __license__   = 'BSD'
  7.  
  8.  
  9. """
  10.     Antamedia Automatic Login Bot
  11.  
  12. - Antamedia is a software used by some ISP's
  13.  to auto disconnect users connected to a network after some idle time.
  14.  Users who are disconnected from the network need to reconnect
  15.  with required credentials in order to regain their internet connection.
  16.  
  17. - This script aims to solve that issue by acting as a headless browser & filling in the form
  18.   on the users behalf at regular intervals if the connection is found to be disconnected.  
  19.  
  20. - Utilizes the mechanize library in python, which may have to be installed manually.
  21.  
  22. """
  23.  
  24. from time import sleep
  25. from datetime import datetime
  26. import mechanize, sys
  27.  
  28. class AutoConnectionBot(object):
  29.  
  30.     def __init__(self, sleep_time=300, usr="", pwd=""):
  31.  
  32.         self.sleep_time = sleep_time
  33.         self.usr = usr
  34.         self.pwd = pwd
  35.  
  36.     def setBrowser(self):
  37.         self.br = mechanize.Browser()
  38.         self.br.set_handle_equiv(True)
  39.         self.br.set_handle_redirect(True)
  40.         self.br.set_handle_referer(True)
  41.         self.br.set_handle_robots(False)
  42.         self.br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20110506 Firefox/4.0.1')]
  43.         self.br.set_debug_http(False)
  44.  
  45.     def Main(self):
  46.  
  47.         while True:
  48.             try:
  49.                 self.setBrowser()
  50.                 print '\n'
  51.                 print "*"*100
  52.                 print "[*] Performing Antamedia Connection Check at %s" % datetime.now()
  53.                 self.br.open("http://www.google.com/")
  54.  
  55.                 if (self.br.title().strip() == 'Google'):
  56.                     print '[+] Already connected to Antamedia'
  57.                     print "[*] Sleeping for %d seconds." % (self.sleep_time)
  58.                     print "="*100
  59.                     self.br.close()
  60.                     sleep(self.sleep_time)
  61.                 else:
  62.                     print '[!] Attempting to connect to Antamedia'
  63.  
  64.                     self.br.select_form(nr=0)
  65.                     self.br['userlogin'] = self.usr
  66.                     self.br['userpass']  = self.pwd
  67.                     self.br.submit()
  68.  
  69.                     self.br.open("http://www.google.com/")
  70.  
  71.                     if (self.br.title().strip() == 'Google'):
  72.                         print '[+] Already connected to Antamedia'
  73.                         print "[*] Sleeping for %d seconds." % (self.sleep_time)
  74.                         print "="*100
  75.                         self.br.close()
  76.                         sleep(self.sleep_time)
  77.                     else:
  78.                         print '[!] IP Address Conflict Detected.'
  79.                         print '[*] Retrying in %d seconds.' % (self.sleep_time)
  80.                         print "="*100
  81.                         self.br.close()
  82.                         sleep(self.sleep_time)
  83.  
  84.             except (KeyboardInterrupt):
  85.                 print '[!] Keyboard Interrupt Detected - Quitting..'
  86.                 sys.exit(0)
  87.             except (IOError):
  88.                 print "[!] Error occured while connecting to Network."
  89.                 print "[*] Retrying in %d seconds." % (self.sleep_time)
  90.                 print "="*100
  91.                 sleep(self.sleep_time)
  92.             except (Exception):
  93.                 print "[!] Unknown Error occured - Quitting.."
  94.                 print "="*100
  95.                 sys.exit(1)
  96.  
  97. if __name__ == '__main__':
  98.     Bot = AutoConnectionBot(usr="RoomNumber", pwd="SomePassword")
  99.     Bot.Main()
Advertisement
Add Comment
Please, Sign In to add comment