by davidbeckam on Mon Aug 31, 2009 7:20 am
I'm mainly a PHP programmer however I've been dabbling in Python and absolutely love how simple everything is. I wrote a email filter to catch certain mail in about 30 minutes and now I have this new script which logs me into my campus' BlueSocket WIFI automatically.... Basically I was just wondering are there any ways I could have cut this down a bit more (maybe how I dealt with the gateway handling?)
Code:
#!/usr/bin/python
import urllib2, urllib, socket
username = 'USERNAME'
password = 'PASWORD'
ip = socket.gethostbyname(socket.gethostname())
gateway = ip.split('.')
gateway[3]='1'
gatewayip = gateway[0:4]
gate_ip = ".".join(gatewayip)
gatesip = "http://",gate_ip,"/login.pl"
g = "".join(gatesip)
login = urllib.urlencode({'customlogin': 1, '_FORM_SUBMIT': 1, 'which_form': 'reg', 'destination': '', 'error': '', 'source': '128.186.232.83','SUBMIT': 'Log In', 'bs_name': username, 'bs_password': password});
e = urllib2.urlopen(g, login)
print "Tried...",g
print "Logged in!"
Thanks in advance.