V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
evin
V2EX  ›  Python

如何用 python 自动 post,完成网页认证上网?

  •  
  •   evin · 2016-03-11 20:41:52 +08:00 · 6417 次点击
    这是一个创建于 2974 天前的主题,其中的信息可能已经有所发展或是发生改变。

    学校上网需要 web 认证,想是否可以通过 python 模拟发包 写个 py 文件放进路由器里自动认证,然后中继 wifi 让多台设备连接上网
    这是我抓包的结果

    20 条回复    2016-03-17 13:25:03 +08:00
    evin
        1
    evin  
    OP
       2016-03-11 20:46:34 +08:00
    import requests

    Target='http://auth.wifi.com/40/login.cgi?x=8576198279906591137598122957861719&c=33825515'
    Data={
    "portal_subtype": "account",
    "user_name": "账号",
    "password": "密码"
    }
    r = requests.post(Target,Data)
    print r.text


    这样写对吗?
    xia0chun
        2
    xia0chun  
       2016-03-11 20:50:25 +08:00 via iPhone
    最好加上 UA ,以防万一被封
    evin
        3
    evin  
    OP
       2016-03-11 21:01:27 +08:00
    @xia0chun
    ```
    s = requests.session()
    data = {"portal_subtype": "account","user_name": "账号","password": "密码"
    }
    res=s.post('http://auth.wifi.com/40/pc.html?x=3180345486836446256183969493333751&c=78633491',data);//认证的网页
    s.get('http://auth.wifi.com/40/login.cgi?x=8576198279906591137598122957861719&c=33825515');
    ```
    为什么 终端 python 运行 告诉我 没有定义 requests
    xia0chun
        4
    xia0chun  
       2016-03-11 21:05:40 +08:00
    @evin 你要先 import requests ,如果没有安装 requests 的话,要先安装。
    evin
        5
    evin  
    OP
       2016-03-11 21:06:59 +08:00
    @xia0chun 原来是忘记安装 request 模块了了😂
    wenyu1001
        6
    wenyu1001  
       2016-03-11 21:14:55 +08:00
    pip install requests
    =========================

    #!/usr/bin/env python
    # encoding: utf-8

    import requests


    def test():
    d = {'key':'value'}
    headers = {'user-agent': 'my-app/0.0.1'}
    url = 'http://httpbin.org/post'

    r = requests.post(url, headers=headers, data=d)

    if r.status_code == 200:
    print "ok"

    if __name__ == "__main__":
    test()
    evin
        7
    evin  
    OP
       2016-03-11 21:34:30 +08:00
    @wenyu1001 谢谢 测试发现 密码是加密发送的😂 。。。。
    Kilerd
        8
    Kilerd  
       2016-03-11 21:55:27 +08:00
    看你发的第一张图就知道密码是加密了的, 居然不知道加密方式就去试程序。
    lhbc
        9
    lhbc  
       2016-03-11 22:36:51 +08:00
    路由器跑 Python 多累啊,这事不是 curl 最合适吗?
    binux
        10
    binux  
       2016-03-11 22:40:38 +08:00
    用 web 认证的 wifi, 连接不加密的。
    可以搞到一大堆账号了啊
    VYSE
        11
    VYSE  
       2016-03-11 22:56:09 +08:00
    LZ 你这个 CHARLES 包括 CHROME 右键不是都有转成 curl 的选项么,根本不用上 PYTHON 啊
    Izual
        12
    Izual  
       2016-03-12 00:30:47 +08:00   ❤️ 1
    chrome 浏览器 F12 然后 copy as curl ?
    evin
        13
    evin  
    OP
       2016-03-12 16:10:26 +08:00
    @VYSE 😂 我是菜鸟 ,居然还有这个功能 谢谢 提示
    evin
        14
    evin  
    OP
       2016-03-12 16:10:34 +08:00
    @Izual 😂 我是菜鸟 ,居然还有这个功能 谢谢 提示
    mxonline
        15
    mxonline  
       2016-03-12 22:05:51 +08:00
    用 open-wrt +wifidog 就行了,没必要上 Python 啊
    evin
        16
    evin  
    OP
       2016-03-13 12:16:09 +08:00
    @mxonline wifidog 是搭建认证好吗
    mxonline
        17
    mxonline  
       2016-03-14 22:34:19 +08:00
    @evin wifidog 是开源的,而且认证端支持 php,可以看下文档
    1stlulu
        18
    1stlulu  
       2016-03-16 22:40:22 +08:00 via Android   ❤️ 1
    楼主我受你鼓舞给蔽校写了个 Android 端的一键连网
    https://play.google.com/store/apps/details?id=xyz.jilulu.jamesji.netify
    evin
        19
    evin  
    OP
       2016-03-17 09:06:24 +08:00
    @1stlulu 感谢,但是我是 mac 和 ios 😂 本来想放进路由器里的
    1stlulu
        20
    1stlulu  
       2016-03-17 13:25:03 +08:00 via Android
    @evin “蔽校”不是“贵校”
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2462 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 14:28 · PVG 22:28 · LAX 07:28 · JFK 10:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.