模拟登陆校园网 图个省事方便

本文介绍了一个使用Python编写的简单脚本,该脚本能够实现校园网的自动化登录过程。通过设置用户名和密码,利用urllib2和cookielib模块发送POST请求到指定的URL,从而完成登录操作。

原理很简单 就是发个包


#coding=utf-8

import urllib2,urllib
import cookielib
import time


class monilogin:
    def __init__(self,user,password):
        self.ipAddress='210.28.18.6'
        self.url='http://'+str(self.ipAddress)+':801/eportal/?c=ACSetting&a=Login&wlanuserip'\
        '=null&wlanacip=null&wlanacname=null&port=&iTermType=1&session=ac11982e-000000000000-0000'
        
        self.user=user
        self.password=password
        
        print 'target url:',self.url
        
        self.user_agent='Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'  
        self.headers={ 'User-Agent' : self.user_agent }  
        
        self.postdata=urllib.urlencode({
                     'DDDDD':self.user,
                     'upass':self.password,
                     'R1':'0',
                     'R2':'',
                     'R6':'0',
                     'para':'00',
                     '0MKKey':'123456',         
        })
        print 'postdata:',self.postdata
        self.cookies = cookielib.CookieJar()
        self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookies))
         
    def start(self):
        
        request  = urllib2.Request(
            url = self.url,
            data = self.postdata,
            headers=self.headers
            )

        result=self.opener.open(request)
        
        #print result.read().decode('gbk')


 
 
if __name__=='__main__':
        user='xxxxxxxxx'
        password='xxxxxx'
        moniqi=monilogin(user,password)
        moniqi.start()   
	print 'succeed'
        time.sleep(5)
         


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值