利用python编写东北大学自动联网程序

来源:互联网 发布:淘宝交换的主板靠谱吗 编辑:程序博客网 时间:2024/05/12 07:12

在无意中利用firebug发现学校的ip控制网关是利用post命令明文传输的。
post_ip
便想着可以利用python实现一个自助联网的程序,以方便每天的联网操作。
学校的一般联网包括两个操作一个是断开所有连接,一个是创建连接,分别对应post参数中的‘disconnectall’和‘connect’。学校系统默认只能维持一个连接,所以为了使程序不至于在有链接的状况连接失败,所以在连接之前要先进行断开所有连接的操作。
代码如下:

#! user/bin/env python#! -*- coding:utf-8 -*-import urllibimport urllib2url='http://ipgw.neu.edu.cn/ipgw/ipgw.ipgw'post={'operation':'disconnectall','password':'这里写下自己的密码','range':'2','timeout':'1','uid':'这里写下自己的用户名'}data=urllib.urlencode(post)req=urllib2.urlopen(url,data)response=req.read()print responseurl='http://ipgw.neu.edu.cn/ipgw/ipgw.ipgw'post={'operation':'connect','password':'这里写下自己的密码','range':'2','timeout':'1','uid':'这里写下自己的用户名'}data=urllib.urlencode(post)req=urllib2.urlopen(url,data)response=req.read()print responseraw_input('press any key to continue')
0 0
原创粉丝点击