USB 上网卡必须处于 HiLink/NETWork 模式,串口模式无法使用;B2368-22 和 B593s-22 因固件不兼容明确不支持;调用需要授权的接口时,要在连接 URL 中带上用户名和密码,否则会抛异常。
huawei-lte-api
SalamekLGPL-3.0活跃维护用 Python 调用华为 LTE 路由器(LAN/WAN)的接口,读取信号、流量、设备状态等信息,省去自己抓包逆向的麻烦。
API For huawei LAN/WAN LTE Modems
pip install huawei-lte-apiREADME 未说明运行本库的硬件要求;它通过 HTTP 访问华为 LTE 设备,USB 上网卡需支持 HiLink(NETWork)模式,串口模式不可用。
用 Python 调用华为 LTE 路由器和上网卡,收发短信、查流量和信号
用 Python 调用华为 LTE 路由器(LAN/WAN)的接口,读取信号、流量、设备状态等信息,省去自己抓包逆向的麻烦。
核心能力
- 通过 HTTP 连接路由器,按 API 分组调用设备接口
- 读取信号强度、设备信息、流量用量等状态
- 支持发送和接收短信
- 提供 Client 封装,简化对各 API 分组的访问
- 已有 TypeScript 和 PHP 移植版本可参考
容易踩的坑
- 2.0.0huawei-lte-api 2.0.0最新正式版2026-08-13 · 2026-08-13 22:02 UTC
huawei-lte-api 2.0.0
This major release adds support for supplementary Unicode characters, new API endpoints and examples, modernizes the development toolchain, and removes APIs that have been deprecated for several years.
Breaking changes
AuthorizedConnectionremovedReplace:
from huawei_lte_api.AuthorizedConnection import AuthorizedConnection connection = AuthorizedConnection(url, username, password)with:
from huawei_lte_api.Connection import Connection connection = Connection(url, username, password)login_on_demandremovedThe deprecated
login_on_demandargument had no effect and has been removed fromConnection.Deprecated device methods removed
Replace:
device.control(mode) device.reboot()with:
device.set_control(mode) device.set_control(ControlModeEnum.REBOOT)Integer SMS sort types removed
Sms.get_sms_list(sort_type=...)now requiresSortTypeEnum:from huawei_lte_api.enums.sms import SortTypeEnum messages = client.sms.get_sms_list(sort_type=SortTypeEnum.DATE)Unicode support
Requests containing characters outside the Basic Multilingual Plane, including emoji, are now encoded using CESU-8 for compatibility with Huawei routers.
CESU-8 surrogate pairs in router responses are converted to standard UTF-8 before XML parsing.
New API endpoints
Diagnosis.wan_service_name()Monitoring.onekey_diag()Security.acl()User.rule()Voice.volte()WLan.guesttime_setting()
Fixes and improvements
- Fixed the TimeRule API endpoint.
- Added request and response debug logging.
- Improved readable signal-mode handling.
- Improved the data-dump example and error reporting.
- Added Huawei 5G CPE6 to the supported-device list.
- Added documentation for API endpoints.
New examples
device_signal.py— display detailed signal information.read_sms.py— read SMS messages from the router.
Development and compatibility
- Added Python 3.13 and Python 3.14 testing.
- Migrated package configuration to
pyproject.toml. - Migrated linting and formatting to Ruff.
- Expanded strict mypy checking.
- Added core tests for requests, responses, CSRF handling, authentication, error mapping, and CESU-8.
- The test suite now contains 50 tests.
New Contributors
- @amelchio made their first contribution in https://github.com/Salamek/huawei-lte-api/pull/266
Full Changelog: https://github.com/Salamek/huawei-lte-api/compare/1.11.0...2.0.0
- 1.11.02025-03-15 · 2025-03-15 20:00 UTC
查看更新说明
What's Changed
- reconnect api by @farlongsignal in https://github.com/Salamek/huawei-lte-api/pull/227
- FAILED sms status by @alex-eri in https://github.com/Salamek/huawei-lte-api/pull/230
- Update README.md by @rezajax in https://github.com/Salamek/huawei-lte-api/pull/232
- Enhance MAC filtering and add filtered devices retrieval methods by @TheLime1 in https://github.com/Salamek/huawei-lte-api/pull/231
New Contributors
- @farlongsignal made their first contribution in https://github.com/Salamek/huawei-lte-api/pull/227
- @alex-eri made their first contribution in https://github.com/Salamek/huawei-lte-api/pull/230
- @rezajax made their first contribution in https://github.com/Salamek/huawei-lte-api/pull/232
Full Changelog: https://github.com/Salamek/huawei-lte-api/compare/1.10...1.11.0
- 1.102024-08-22 · 2024-08-22 00:07 UTC
查看更新说明
What's Changed
- examples: add an example script for sending ussd codes by @mmubarak0 in https://github.com/Salamek/huawei-lte-api/pull/218
- wlan_guide_settings api by @timvlaer in https://github.com/Salamek/huawei-lte-api/pull/219
- Update dialup profile by @timvlaer in https://github.com/Salamek/huawei-lte-api/pull/221
- Fix: Unlock PIN method returning 101006 Unknown Error by @NaturalT314 in https://github.com/Salamek/huawei-lte-api/pull/224
New Contributors
- @mmubarak0 made their first contribution in https://github.com/Salamek/huawei-lte-api/pull/218
- @timvlaer made their first contribution in https://github.com/Salamek/huawei-lte-api/pull/219
- @NaturalT314 made their first contribution in https://github.com/Salamek/huawei-lte-api/pull/224
Full Changelog: https://github.com/Salamek/huawei-lte-api/compare/1.9.3...1.10
- 1.8.1New release2024-01-07 · 2024-01-07 15:20 UTC
查看更新说明
What's Changed
- examples: add an example script for setting the network mode and 4G bands by @lazka in https://github.com/Salamek/huawei-lte-api/pull/192
- Support b28 in net_mode.py example command by @jeffreykog in https://github.com/Salamek/huawei-lte-api/pull/194
- Add Huawei B612-233 to supported devices by @TheLime1 in https://github.com/Salamek/huawei-lte-api/pull/202
- fixed
set_multi_macfilter_settingsdocumentation + added an example by @TheLime1 in https://github.com/Salamek/huawei-lte-api/pull/204
New Contributors
- @lazka made their first contribution in https://github.com/Salamek/huawei-lte-api/pull/192
- @jeffreykog made their first contribution in https://github.com/Salamek/huawei-lte-api/pull/194
- @TheLime1 made their first contribution in https://github.com/Salamek/huawei-lte-api/pull/202
Full Changelog: https://github.com/Salamek/huawei-lte-api/compare/1.7.3...1.8.1
- 1.7New release2023-06-13 · 2023-06-13 00:39 UTC
查看更新说明
What's Changed
- Require Python >= 3.7 by @scop in https://github.com/Salamek/huawei-lte-api/pull/166
- Add Net.set_network by @scop in https://github.com/Salamek/huawei-lte-api/pull/168
- Suppress login required and not supported on UserSession close by @scop in https://github.com/Salamek/huawei-lte-api/pull/169
- Clarify provided requests_session closure doc by @scop in https://github.com/Salamek/huawei-lte-api/pull/170
- Add some WPS setters by @scop in https://github.com/Salamek/huawei-lte-api/pull/182
- ci: test with Python 3.12 by @scop in https://github.com/Salamek/huawei-lte-api/pull/183
- Update README.md by @j-broo in https://github.com/Salamek/huawei-lte-api/pull/185
- add: add vpn toggle status method by @mehdiirh in https://github.com/Salamek/huawei-lte-api/pull/189
New Contributors
- @j-broo made their first contribution in https://github.com/Salamek/huawei-lte-api/pull/185
- @mehdiirh made their first contribution in https://github.com/Salamek/huawei-lte-api/pull/189
Full Changelog: https://github.com/Salamek/huawei-lte-api/compare/1.6.11...1.7
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
huawei-lte-api
API For huawei LAN/WAN LTE Modems, you can use this to simply send SMS, get information about your internet usage, signal, and tons of other stuff
Please consider sponsoring if you're using this package commercially, my time is not free :) You can sponsor me by clicking on "Sponsor" button in top button row. Thank You.
Tested on:
3G/LTE Routers:
- Huawei B310s-22
- Huawei B311-221
- Huawei B315s-22
- Huawei B525s-23a
- Huawei B525s-65a
- Huawei B715s-23c
- Huawei B528s
- Huawei B535-232
- Huawei B628-265
- Huawei B612-233
- Huawei B818-263
- Huawei E5180s-22
- Huawei E5186s-22a
- Huawei E5576-320
- Huawei E5577Cs-321
- Huawei E8231
- Huawei E5573s-320
- SoyeaLink B535-333
3G/LTE USB sticks:
(Device must support NETWork mode aka. "HiLink" version, it wont work with serial mode)
- Huawei E3131
- Huawei E8372h-608
- Huawei E3372
- Huawei E3531
- Huawei E5530As-2
5G Routers:
- Huawei 5G CPE Pro 2 (H122-373)
- Huawei 5G CPE Pro (H112-372)
- Huawei 5G CPE6 (H165-383)
(probably will work for other Huawei LTE devices too)
Will NOT work on:
LTE Routers:
- Huawei B2368-22 (Incompatible firmware, testing device needed!)
- Huawei B593s-22 (Incompatible firmware, testing device needed!)
Installation
PIP (pip3 on some distros)
pip install huawei-lte-api
Repository
You can also use these repositories maintained by me
Debian and derivatives
Add repository by running these commands
wget -O- https://repository.salamek.cz/deb/salamek.gpg | sudo tee /usr/share/keyrings/salamek-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/salamek-archive-keyring.gpg] https://repository.salamek.cz/deb/pub all main" | sudo tee /etc/apt/sources.list.d/salamek.cz.list
And then you can install a package python3-huawei-lte-api
apt update && apt install python3-huawei-lte-api
Archlinux
Add repository by adding this at end of file /etc/pacman.conf
[salamek]
Server = https://repository.salamek.cz/arch/pub/any
SigLevel = Optional
and then install by running
pacman -Sy python-huawei-lte-api
Gentoo
emerge dev-python/huawei-lte-api
Usage
from huawei_lte_api.Client import Client
from huawei_lte_api.Connection import Connection
# with Connection('http://192.168.8.1/') as connection: For limited access, I have valid credentials no need for limited access
with Connection("http://admin:[email protected]/") as connection:
client = Client(connection) # This just simplifies access to separate API groups, you can use device = Device(connection) if you want
print(client.device.signal()) # Can be accessed without authorization
print(client.device.information()) # Needs valid authorization, will throw exception if invalid credentials are passed in URL
# For more API calls just look on code in the huawei_lte_api/api folder, there is no separate DOC yet
Result dict
{
"DeviceName": "B310s-22",
"SerialNumber": "MY_SERIAL_NUMBER",
"Imei": "MY_IMEI",
"Imsi": "MY_IMSI",
"Iccid": "MY_ICCID",
"Msisdn": None,
"HardwareVersion": "WL1B310FM03",
"SoftwareVersion": "21.311.06.03.55",
"WebUIVersion": "17.100.09.00.03",
"MacAddress1": "EHM:MY:MAC",
"MacAddress2": None,
"ProductFamily": "LTE",
"Classify": "cpe",
"supportmode": None,
"workmode": "LTE",
}
Code examples
Some code examples are in /examples folder
Monitoring
- Monitoring traffic and signal https://github.com/littlejo/huawei-lte-examples
- Set band, show signal level and bandwidth for Huawei mobile broadband B525s-23a. https://github.com/octave21/huawei-lte
- Application that monitors Internet connectivity and restarts router when internet is not reachable https://github.com/Salamek/netkeeper
- Monitoring app with nice TUI interface (just like htop) https://github.com/pdo-smith/5gtop
SMS
- Relay received SMS into your email https://github.com/chenwei791129/Huawei-LTE-Router-SMS-to-E-mail-Sender
Ports to other languages
- TypeScript/JavaScript https://github.com/Salamek/huawei-lte-api-ts
- PHP https://github.com/icetee/huawei-lte-api-php
Donations
- 250 CZK (9.79 EUR) for B535-232 fund, thx @larsvinc !
- 371,69 CZK (14.32 EUR) by Oleg Jusaew
- 292 CZK (11.50 EUR) by Toth-Mate Akos
- 441 CZK (18.12 EUR) by Olexandr Shamin