石家庄定制网站建设服务,wordpress导航横着,最具价值的网站建设,中国关键词网站在本文中#xff0c;我们将展示如何使用Python编写一个简单的脚本来实现Linux下的惠尔顿上网认证。以下是我们需要的参数和值#xff1a;
wholeton_host: 惠尔顿服务器地址#xff0c;例如 192.168.10.10wholeton_user: 用户名#xff0c;例如 AABBCCwholeton_pass: 密码我们将展示如何使用Python编写一个简单的脚本来实现Linux下的惠尔顿上网认证。以下是我们需要的参数和值
wholeton_host: 惠尔顿服务器地址例如 192.168.10.10wholeton_user: 用户名例如 AABBCCwholeton_pass: 密码例如 231313wholeton_ip: 客户端IP地址例如 10.10.1.1wholeton_mac: 客户端MAC地址例如 aa:bb::cc:dd:ee:ffupdate_secs: 认证更新间隔时间秒例如 28800 8小时
以下是完整的Python代码
#!/usr/bin/python
# -*- coding: utf-8 -*-import sys
import socket
from datetime import datetime
from uuid import getnode
import urllibtry:import urllib2
except Exception:from urllib import request as urllib2
try:import Cookie as cookies
except Exception:from http import cookies
import websocket
import jsonwholeton_host 192.168.10.10
wholeton_user AABBCC
wholeton_pass 231313
wholeton_ip
wholeton_mac
update_secs 28800def url_encode(obj):try:return urllib.urlencode(obj)except Exception:return urllib.parse.urlencode(obj)def get_ip():return 10.10.1.1def get_mac():return aa:bb::cc:dd:ee:ffif not wholeton_ip:wholeton_ip get_ip()if not wholeton_mac:wholeton_mac get_mac()uri_keys {id: 0, url: mail.126.com, user: wholeton_ip, mac: wholeton_mac}
uri_data url_encode(uri_keys).replace(%3A, :)auth_data url_encode({param[UserName]: wholeton_user, param[UserPswd]: wholeton_pass, uri: uri_data, force: 0})
# convert for python 3
if sys.version_info[0] 3:auth_data auth_data.encode(ascii)def main():ws Noneloop Truetry:while loop:resp urllib2.urlopen(http:// wholeton_host /user-login-auth? uri_data, timeout5, dataauth_data)# get session cookiecookie cookies.SimpleCookie()cookie.load(resp.info()[Set-Cookie])resp_data resp.read()if resp_data:print(Login response:)print(resp_data)ws websocket.WebSocket()ws.connect(ws:// wholeton_host /go-ws/user-auth,cookiefms_session cookie.get(fms_session).value, originhttp:// wholeton_host)dt_start datetime.now()while ws:try:ws_data ws.recv()except KeyboardInterrupt:loop Falsebreakexcept:breakif ws_data:dt_now datetime.now()if (dt_now - dt_start).seconds update_secs:breakprint(dt_now)print(ws_data)ws_obj json.loads(ws_data)if ws_obj and ws_obj[type] logged-out:breakif ws:ws.close()ws Noneexcept KeyboardInterrupt:passif ws:ws.close()if __name__ __main__:main()这个脚本首先定义了所需的参数和函数然后在main函数中实现了认证流程。它会周期性地向惠尔顿服务器发送认证请求并在接收到服务器响应后解析并处理数据。
要运行此脚本请将上述代码保存为一个.py文件然后在Linux终端中使用python命令执行该文件。请注意你需要根据实际情况修改wholeton_host、wholeton_user、wholeton_pass、wholeton_ip和wholeton_mac等参数的值。
启动程序
#前台启动
python3 wholeton-auth.py
python2 wholeton-auth.py
python wholeton-auth.py
#后台启动
nohup python3 wholeton-auth.py 21 /dev/null 离线安装python依赖可参考
#离线安装Python依赖以six和websocket-client为例
https://yjtzfywh.blog.csdn.net/article/details/135225376