Source

cmcc / cmcc_xiaoxia.py

#!/usr/bin/env python
import cookielib, urllib2
import re
import os
import random
import time

username = ''
passwd = ''

cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))

test = opener.open('http://xiaoxia.org')
data = test.read()
userip = re.search(r'NAME="wlanuserip" value="(.+)">', data).group(1)
acname = re.search(r'NAME="wlanacname" value="(.+)">', data).group(1)
acip = re.search(r'NAME="wlanacip" value="(.+)">', data).group(1)

url = os.path.join(os.path.dirname(test.url), 'index.jsp')
data = 'wlanuserip=%s&wlanacname=%s&wlanacip=%s' % (userip, acname, acip)
print 'opening', url, data
data = opener.open(url, data).read()

url = os.path.join(os.path.dirname(test.url), 'jsp/do_login.jsp')
data = 'bpssUSERNAME=%s&bpssBUSPWD=%s&' +\
 'Submit=\xb5\xc7\xc2\xbc&bpssLoginType=1' % (username, passwd)
print 'opening', url, data
data = opener.open(url, data).read()
print 'result', data