大学城的自动网关登陆脚本

来源:互联网 发布:for数组去重 编辑:程序博客网 时间:2024/04/30 10:16

题前

不提供帐号密码,
仅仅是一个用于自动登录的python脚本, 用于主机的自动登录

版本0.1

  • 实现了基本登陆功能
  • 仅用于python2.7
#!/usr/bin/env python2# encoding: utf-8import urllibimport urllib2import cookielib# 登录urllgurl = r'http://10.0.10.66/cgi-bin/srun_portal'def createUser(username, password):    # headers    hds = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36'}    # post data    postdata = \        {'action':'login',         'username':'将本文字改成帐号',         'password':'将本文字改成密码',         'ac_id':'3',         'type':'1',         'wbaredirect':'',         'mac':'',         'user_ip':'',         'nas_ip':'',         'pop':'1',         'is_ldap':'1',         'nas_init_port':'1'}     return hds, urllib.urlencode(postdata)def login(username, password):    # Create Browser    # Cookie    cookie = cookielib.CookieJar()    cookie_handler = urllib2.HTTPCookieProcessor(cookie)    opener = urllib2.build_opener(cookie_handler)    # Fill user information    headers, postdata = createUser(username, password)    req = urllib2.Request(url = lgurl, data = dt, headers = hds)    # login    response = opener.open(req)    page = response.read()    print pagelogin('username', 'password')

如果输出是

login_ok

说明登录成功了.

下一步

  • python3支持
0 0