Skip to main content

BUPT Gateway Login

用于登录北京邮电大学校园网的命令行程序。跨平台,仅 Python 3。

可以从文件读取用户名和密码自动登录,或者通过参数指定用户名密码,也可以交互式输入用户名密码。

更新:

  • 0.1.0:增加 check_net_account 函数,用于通过学校 VPN 登录页面检查上网账号是否正确。

已知问题:

  • check_net_account 在校园网某些网络环境下不能工作。(在某些服务器上请求该页面,可以建立连接但服务器无响应)

安装

直接使用 pip 安装

pip install buptgw


如果有问题可以使用 pypi 源,且支持 IPv6,校园网电脑无需登录网络即可访问

pip install -i https://pypi.org/simple buptgw

如果你没有 root 权限,可以添加 --user 参数即

pip install buptgw --user 或 pip install -i https://pypi.org/simple buptgw --user

另外在某些比较旧版本系统上 pip 指向 pip2,所以需要使用 pip3 代替命令中的 pip

使用

登录 buptgw -i

退出 buptgw -o

保存用户名密码到文件(下次登录无需手动输入) buptgw -w

全部参数

Usage: buptgw -i|-o|-w  [-c <config_file>] [-u <username>] [-p <password>]
    -i                login
    -o                logout
    -w                write username and password to config file
    -c <config_path>  config file path, optional, defualt is ~/.buptgw
    -u <username>
    -p <password>

参数 -i 代表登录 -o 代表退出,-w 把用户名和密码写入配置文件,这三个只能选择一个

-c 指定配置文件路径(存储用户名和密码),对 -i 和 -w 有效。如果不指定配置文件,默认为 ~/.buptgw。

-u 指定用户名,如果不指定,会从配置文件读取,如果读取失败则要求输入

-p 指定密码,如果不指定,则要求输入(如果用户名也没输入则一并从配置文件读取)

在 python 中调用

import buptgw

buptgw.login('2018xxxxxx', 'passwd') # 登录,xxx 处替换为正确的学号和密码
buptgw.logout() # 退出

buptgw.check_net_account('2018xxxxxx', 'passwd') # 检查该学号/密码是否匹配,如果匹配返回 True,不匹配返回 False

实现开机自动登录

window

windows 下编写 bat 文件(xxx 处替换为正确的学号和密码),例如保存为 network.bat (注意,不能保存为 buptgw.bat 这样会导致这个文件自己调用自己)

buptgw -i -u 2018xxxxxx -p xxxxx

然后把这个文件放到系统的启动目录下,一般来说,通过运行(快捷键是 win + R),输入 shell:startup 可以快速打开启动目录。

Linux

把登录命令写入 ~/.profile 中

作者博客 :https://es2q.com

Metadata

Release files for buptgw 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for buptgw 0.1.1
File Size Uploaded
buptgw-0.1.1.tar.gz 5.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for buptgw 0.1.1
File Interpreter ABI Platform
buptgw-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.9 kB

Release files / buptgw-0.1.1.tar.gz

Download URL buptgw-0.1.1.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
669d5a272721a364208874d13556123b36c76047072652be25221bf0d591bf35
BLAKE2b-256 checksum
How to use checksums
7ad0802dda4a46b31f73e1f25fa0eec45fcfe4c24991ef03048443a5bb90fce8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

Release files / buptgw-0.1.1-py3-none-any.whl

Download URL buptgw-0.1.1-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d54c18204104b143304b37a2a976d65d0f1d6014fe854169be98863d1df373ab
BLAKE2b-256 checksum
How to use checksums
b4e4c7dc7d1e61c8863675bae6e7a455d14487485ae183b1d53db248455522c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page