深澜登陆脚本

#! /usr/bin/python
# -*- coding: utf-8 -*-

"""深澜登陆脚本"""

import urllib,urllib2,re,cookielib,time

url3 = 'http://10.255.44.33/'

cookies = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookies))
urllib2.install_opener(opener)
opener.addheaders.append(("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0"))
opener.addheaders.append(("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"))
opener.addheaders.append(("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3"))
opener.addheaders.append(("Accept-Encoding", "gzip, deflate"))
opener.addheaders.append(("Cookie", "srun_login=13010321007|Xwljxwlj||||6"))

def QueryUserInfo():
    f = opener.open('http://10.255.44.33/cgi-bin/rad_user_info')
    ret = f.read()
    if (ret == 'not_online'):
        return ret
    else:
          return 'online'

def login(status):
    if(status == 'not_online'):
        data={
            'action':    'login'
            ,'username':    'account'
            ,'password':    'password'
            ,'ac_id':    '6'
            ,'type':    '1'
            ,'wbaredirect':    ''
            ,'mac':    '' 
            ,'user_ip' : ''                     
             }
        data=urllib.urlencode(data)
        request = urllib2.Request(
            url     = 'http://10.255.44.33/cgi-bin/srun_portal',        
            data    = data)
        data = opener.open(request).read()
        filepath = "login.log"
        captcha_file = open(filepath, "wb+")
        captcha_file.write(data)
        captcha_file.close()
    
if __name__ == "__main__":
    status = QueryUserInfo()
    login(status)

发表评论

电子邮件地址不会被公开。 必填项已用*标注