Skip to content

Instantly share code, notes, and snippets.

@feisuzhu
Created May 24, 2012 13:19
Show Gist options
  • Save feisuzhu/2781505 to your computer and use it in GitHub Desktop.
Save feisuzhu/2781505 to your computer and use it in GitHub Desktop.
Autologin for ChinaNet
#!/usr/bin/python2
# -*- coding: utf-8 -*-
import urllib
import urllib2
import time
mapping = {
u'全国中心': u'zx',
u'全国': u'china',
u'新疆': u'xj',
u'北京': u'bj',
u'天津': u'tj',
u'河北': u'he',
u'山西': u'sx',
u'内蒙古': u'nm',
u'辽宁': u'ln',
u'吉林': u'jl',
u'黑龙江': u'hl',
u'湖北': u'hb',
u'湖南': u'hn',
u'河南': u'ha',
u'江苏': u'js',
u'山东': u'sd',
u'安徽': u'ah',
u'上海': u'sh',
u'浙江': u'zj',
u'福建': u'fj',
u'江西': u'jx',
u'海南': u'hi',
u'广西': u'gx',
u'四川': u'sc',
u'重庆': u'cq',
u'贵州': u'gz',
u'云南': u'yn',
u'西藏': u'xz',
u'陕西': u'sn',
u'甘肃': u'gs',
u'青海': u'qh',
u'宁夏': u'nx',
u'澳门': u'am',
}
def must_succeed(f):
def _wrapper(*a, **k):
while True:
try:
return f(*a, **k)
except:
pass
print '!! Func %s failed, retry' % f.__name__
return _wrapper
@must_succeed
def login(acct, pwd, loc):
url = 'https://wlan.ct10000.com/phonelogin.do'
data = {
'phoneName': acct,
'phoneSavePass': 'on',
'phoneProvince': mapping[loc],
'phonePass': pwd,
}
data = 'phoneType=&' + urllib.urlencode(data)
rst = urllib2.urlopen(url, data).read().decode('gbk')
time.sleep(0.3)
if 'loginOut' in rst:
return True
else:
return False
@must_succeed
def logout():
url = 'https://wlan.ct10000.com/loginOut.do'
rst = urllib2.urlopen(url).read()
time.sleep(0.3)
if int(rst) == 10:
return True
else:
return False
good = open('good.txt', 'w')
lst = open('Desktop/wlans.txt', 'r').read()
lst = [i.split(',') for i in lst.strip().decode('utf-8').split('\n')]
for acct, pwd, loc in lst:
print '>>', acct;
if login(acct, pwd, loc):
print 'GOOD!'
time.sleep(1)
logout()
good.write((u'%s,%s,%s\n' % (acct, pwd, loc)).encode('utf-8'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment