Giter VIP home page Giter VIP logo

tsinghuatunet's Introduction

清华校园网自动连接脚本

Tsinghua Tunet auto-connect script

使用方法

  • ./connect.py --gen-config: 生成配置文件;
  • ./connect.py --connect : 使用 net.tsinghua.edu.cn 连接 (推荐);
  • ./connect.py --connect-auth4: 使用 auth4.tsinghua.edu.cn 连接 (仅用于 debug);
  • ./connect.py --connect-auth6: 使用 auth6.tsinghua.edu.cn 连接 (测试中);
  • ./connect.py --test-first: 先测试网络, 不通再连接.

首先用 ./connect.py --gen-config 按提示输入用户名密码生成配置文件, 之后用 ./connect.py --connect./connect.py --test-first 连接.

亮点

  • 更短, 所以更少的八阿哥.
  • 可以先测试网络是否通畅, 失败才重连.
  • 有时清华会强制让人跳转 auth4.tsinghua.edu.cn 连接, 脚本能够自动跳转.
  • 保存密码的哈希而不是明文 (但是使用auth4需要提供密码明文).
  • 支持 ipv4 和 ipv6.

Pain in the neck

  • net 下线之后用 auth4 登陆会显示已经在线.
  • 有时下线时间长了之后连网关都 ping 不通 (不知道为什么), 就更不要说登陆了.
  • 登陆协议中的 ac_id 参数按“正统”的获取方法经常失败,只能通过 net 的返回获得. 如果设置了错误的 ac_id 会返回 'ecode': '', 'error': 'login_error', 'error_msg': 'no_response_data_error', 'res': 'login_error', 如果按照 srun js 的逻辑直接设置 ac_id=1 则返回'ecode': 'E2833', 'error': 'login_error', 'error_msg': 'E2833: Your IP address is not in the dhcp table. Maybe you need to renew the IP address.', 'res': 'login_error'

吐槽

  • 清华的 auth4/auth6 系统是外包的, net 是自己写的, 两个系统并行但是不不悖. 我怀疑 Pain in the neck 中的一些问题就是两个系统并存导致的.
  • 外包的公司是一家叫"深澜" (srun) 的公司,这个公司还负责包括北京理工大学、西北工业大学在内的其他学校的网络管理软件. 网上对其软件的主要吐槽有:
    • 管杀不管埋: 没有 Linux 登陆客户端, 或者说有一个老版的但是不支持新协议;
    • url 参数中有很多没用的部分 (这从代码的 auth4_login 函数的复杂程度可以看出来);
    • 协议中包含数处非标准实现, 使得写第三方登陆脚本很难 (比如代码的 xEncode 函数,根本不知道在做什么).
  • 深澜做这么多非标准操作和自定义 hash 的原因可能是让客户难以更换到其他公司替代之, 的确清华后来试图自己实现 net 也没能完全替代.
  • 我本以为 usereg 中的准入代认证能够提供新的登陆方式, 结果也是深澜的 auth4/6.

感谢

Hosts

In case any one needs related IPs.

166.111.204.120                net.tsinghua.edu.cn
101.6.4.100                    auth4.tsinghua.edu.cn
2402:f000:1:414:101:6:4:100    auth6.tsinghua.edu.cn

使用crontab重复执行脚本

Crontab是Linux系统中基于时间的任务管理程序。使用crontab -e以编辑其配置文件,输入

# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12)
# │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday;
# │ │ │ │ │                                   7 is also Sunday on some systems)
# │ │ │ │ │
# * * * * * <command to execute>
* * * * * cd /dir/to/TsinghuaTunet && ./connect.py --test-first

并且保存退出来让脚本每分钟重复执行。注意要先cd至TsinghuaTunet的文件夹下,否则它的日志文件会留在当前文件夹。使用crontab -l确认配置被保存了。

Usage

  • ./connect.py --gen-config: Generate a configure file including your username and password's hash.
  • ./connect.py --connect : Connect directly.
  • ./connect.py --test-first: First test network by getting webpage of one of Bing, GitHub and Baidu, connect if failed.

First, use ./connect.py --gen-config to generate a configure file. Then try ./connect.py --connect or ./connect.py --test-first.

Feature

  • Short so fewer bugs.
  • Able to test network and reconnect if the test fails.
  • Save password's hash rather than plaintext.

tsinghuatunet's People

Contributors

whymustihaveaname avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

tsinghuatunet's Issues

使用非清华DNS时的解析问题

使用非清华DNS服务器且没有连接网关时,会无法解析 net.tsinghua.edu.cn 和 auth4.tsinghua.edu.cn,应当添加静态IP选项,但又不知道网关服务器的IP会不会经常改变。

Webpage Encoding

The encoding webpage returned is "ISO-8859-1", but actually "GBK" should be used to decode it.

To the one who takes responsibility for the login webpage: "FUCK YOU!"

威联通NAS:Failed to establish a new connection: [Errno 101] Network is unreachable

使用威联通NAS通过SSH命令行联网出现了一些报错,已经配置好了python3环境及依赖包,求解。log如下:

[admin@NAS00B282-WDM 001]# python3 connect.py --test-first
22/10/04 13:21:14 954 [INFO,test_network:225] getting: http://github.com
22/10/04 13:21:14 965 [INFO,test_and_reconnent:247] not online, reconnecting... reason: HTTPConnectionPool(host='github.com', port=80): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7517d9d0>: Failed to establish a new connection: [Errno 101] Network is unreachable'))
22/10/04 13:21:14 966 [INFO,net_login:196] posting: http://net.tsinghua.edu.cn/do_login.php
22/10/04 13:21:14 972 [WARNING,net_login:202] error happened: HTTPConnectionPool(host='net.tsinghua.edu.cn', port=80): Max retries exceeded with url: /do_login.php (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7517ddf0>: Failed to establish a new connection: [Errno 101] Network is unreachable'))
[admin@NAS00B282-WDM 001]# python3 connect.py --connect-auth4
22/10/04 13:21:40 861 [ERROR,auth_login:134] get challenge failed:
Traceback (most recent call last):
File "/share/CACHEDEV1_DATA/.qpkg/Python3/python3/lib/python3.10/site-packages/urllib3/connection.py", line 174, in _new_conn
conn = connection.create_connection(
File "/share/CACHEDEV1_DATA/.qpkg/Python3/python3/lib/python3.10/site-packages/urllib3/util/connection.py", line 95, in create_connection
raise err
File "/share/CACHEDEV1_DATA/.qpkg/Python3/python3/lib/python3.10/site-packages/urllib3/util/connection.py", line 85, in create_connection
sock.connect(sa)
OSError: [Errno 101] Network is unreachable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/share/CACHEDEV1_DATA/.qpkg/Python3/python3/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "/share/CACHEDEV1_DATA/.qpkg/Python3/python3/lib/python3.10/site-packages/urllib3/connectionpool.py", line 386, in _make_request
self._validate_conn(conn)
File "/share/CACHEDEV1_DATA/.qpkg/Python3/python3/lib/python3.10/site-packages/urllib3/connectionpool.py", line 1042, in _validate_conn
conn.connect()
File "/share/CACHEDEV1_DATA/.qpkg/Python3/python3/lib/python3.10/site-packages/urllib3/connection.py", line 358, in connect
self.sock = conn = self._new_conn()
File "/share/CACHEDEV1_DATA/.qpkg/Python3/python3/lib/python3.10/site-packages/urllib3/connection.py", line 186, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x750e1ac0>: Failed to establish a new connection: [Errno 101] Network is unreachable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/share/CACHEDEV1_DATA/.qpkg/Python3/python3/lib/python3.10/site-packages/requests/adapters.py", line 489, in send
resp = conn.urlopen(
File "/share/CACHEDEV1_DATA/.qpkg/Python3/python3/lib/python3.10/site-packages/urllib3/connectionpool.py", line 787, in urlopen
retries = retries.increment(
File "/share/CACHEDEV1_DATA/.qpkg/Python3/python3/lib/python3.10/site-packages/urllib3/util/retry.py", line 592, in increment
raise MaxRetryError(pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='auth4.tsinghua.edu.cn', port=443): Max retries exceeded with url: /cgi-bin/get_challenge?callback=callback&username=$我的账号$&ip=&double_stack=1&
=1664860900849 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x750e1ac0>: Failed to establish a new connection: [Errno 101] Network is unreachable'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/share/CACHEDEV1_DATA/homes/admin/001/connect.py", line 126, in auth_login
g1=requests.get(url,headers=headers,params=params,timeout=TIMEOUT)
File "/share/CACHEDEV1_DATA/.qpkg/Python3/python3/lib/python3.10/site-packages/requests/api.py", line 73, in get
return request("get", url, params=params, **kwargs)
File "/share/CACHEDEV1_DATA/.qpkg/Python3/python3/lib/python3.10/site-packages/requests/api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
File "/share/CACHEDEV1_DATA/.qpkg/Python3/python3/lib/python3.10/site-packages/requests/sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "/share/CACHEDEV1_DATA/.qpkg/Python3/python3/lib/python3.10/site-packages/requests/sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='auth4.tsinghua.edu.cn', port=443): Max retries exceeded with url: /cgi-bin/get_challenge?callback=callback&username=$我的账号$&ip=&double_stack=1&_=1664860900849 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x750e1ac0>: Failed to establish a new connection: [Errno 101] Network is unreachable'))

支持 IPv6

现在 IPV6 还有小问题,但是由于宿舍没有 Tsinghua-IPv6 所以开发有些困难。分支 ipv6 存放着 beta 代码。

ConnectionResetError

经常会报以下错误,似乎在清华校内都连不上清华的网,不知如何解决

./connect.py --connect
[INFO,net_login:37] posting: https://net.tsinghua.edu.cn/do_login.php
[WARNING,net_login:44] error happened: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.