Skip to content

Instantly share code, notes, and snippets.

@lukasklein
Created June 12, 2015 12:33
Show Gist options
  • Save lukasklein/e868a8d64989bf6b515b to your computer and use it in GitHub Desktop.
Save lukasklein/e868a8d64989bf6b515b to your computer and use it in GitHub Desktop.
import random, os, urllib, urllib2, time, getpass
from urlparse import urlparse
rootpass = getpass.getpass()
interface = "en0"
testurl = "http://www.google.com/robots.txt"
stringtotest = "User-agent: *"
def randomMAC():
mac = [ 0x00, 0x16, 0x3e,
random.randint(0x00, 0x7f),
random.randint(0x00, 0xff),
random.randint(0x00, 0xff) ]
return ':'.join(map(lambda x: "%02x" % x, mac))
def setMAC(mac):
os.system("echo '%s' | sudo -S -s ifconfig en0 ether %s"%(rootpass, mac))
def disconnect():
os.system("networksetup -setairportpower %s off"%(interface))
def connect():
os.system("networksetup -setairportpower %s on"%(interface))
def testconnection():
f = urllib2.urlopen(testurl)
return stringtotest==f.read(len(stringtotest))
def login():
print "Logging in..."
# first stage
request = urllib2.Request(testurl)
opener = urllib2.build_opener()
f = opener.open(request)
newurl = f.url
request = urllib2.Request(newurl)
f = opener.open(request)
loginurl = f.url
f = urllib2.urlopen(loginurl)
html = f.read()
for line in html.split("\n"):
if line.find('bs_name') > -1:
bs_name = line[line.find('ue="')+4:line.find('">')]
elif line.find('bs_password') > -1:
bs_password = line[line.find('ue="')+4:line.find('">')]
elif line.find('username1') > -1:
username1 = line[line.find('ue="')+4:line.find('">')]
elif line.find('password1') > -1:
password1 = line[line.find('ue="')+4:line.find('">')]
elif line.find('which_form') > -1:
which_form = line[line.find('ue="')+4:line.find('">')]
elif line.find('destination') > -1:
destination = urllib.quote(line[line.find('ue="')+4:line.find('">')])
elif line.find('method="POST"') > -1:
action = line[line.find('on="')+4:line.find('"" acc')]
data = "bs_name=%s&bs;_password=%s&username1;=%s&password1;=%s&which;_form=%s&destination;=%s&agree;=1&submitButton;=&submitButton.x;=1&submitButton.y;=2"%(bs_name, bs_password, username1, password1, which_form, urllib.quote_plus(testurl))
req = urllib2.Request(url=action, data=data)
o = urlparse(loginurl)
req.add_header('Content-Type', 'application/x-www-form-urlencoded')
req.add_header('Origin', "%s://%s"%(o.scheme, o.netloc))
req.add_header('Referer', loginurl)
req.add_header('User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.186 Safari/535.1')
f = urllib2.urlopen(req)
print "Success! :)"
def reconnect():
setMAC(randomMAC())
disconnect()
connect()
if __name__ == "__main__":
while 1:
if not testconnection():
print "data exceeded, reconnecting..."
reconnect()
time.sleep(10)
login()
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment