Skip to content

Instantly share code, notes, and snippets.

@pejotes
Created April 3, 2024 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pejotes/5bcf64ff6cc4d45daf138e74a3dd71de to your computer and use it in GitHub Desktop.
Save pejotes/5bcf64ff6cc4d45daf138e74a3dd71de to your computer and use it in GitHub Desktop.
zte_info.py
import requests
from requests.exceptions import RequestException
import hashlib
import json
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
class ZTERouter:
def __init__(self, ip, username, password):
self.ip = ip
self.protocol = "http"
self.username = username
self.password = password
self.set_protocol()
self.referer = f"{self.protocol}://{self.ip}/"
def set_protocol(self):
protocols = ["http", "https"]
for protocol in protocols:
url = f"{protocol}://{self.ip}"
try:
response = requests.get(url, timeout=5, verify=False)
if response.ok:
self.protocol = protocol
return
except RequestException:
pass
def hash_password(self, password):
return hashlib.sha256(password.encode()).hexdigest()
def get_version(self):
header = {"Referer": self.referer}
payload = "isTest=false&cmd=wa_inner_version"
response = requests.get(self.referer + f"goform/goform_get_cmd_process?{payload}", headers=header, data=payload, verify=False)
return response.json()["wa_inner_version"]
def get_ld(self):
header = {"Referer": self.referer}
payload = "isTest=false&cmd=LD"
response = requests.get(self.referer + f"goform/goform_get_cmd_process?{payload}", headers=header, data=payload, verify=False)
return response.json()["LD"].upper()
def get_cookie(self, username, password, ld):
header = {"Referer": self.referer}
hashed_password = self.hash_password(password).upper()
zte_pass = self.hash_password(hashed_password + ld).upper()
old_login = self.get_version()
payload = {
'isTest': 'false',
'goformId': 'LOGIN',
'password': zte_pass
}
if username is not None and username != "":
payload['username'] = username
response = requests.post(self.referer + "goform/goform_set_cmd_process", headers=header, data=payload, verify=False)
return "stok=" + response.cookies["stok"].strip('\"')
def get_router_info(self):
cookie = self.get_cookie(username=self.username, password=self.password, ld=self.get_ld())
cmd_url = f"{self.protocol}://{self.ip}/goform/goform_get_cmd_process?isTest=false&cmd=wa_inner_version%2Ccr_version%2Cnetwork_type%2Crssi%2Crscp%2Crmcc%2Crmnc%2Cenodeb_id%2Clte_rsrq%2Clte_rsrp%2CZ5g_snr%2CZ5g_rsrp%2CZCELLINFO_band%2CZ5g_dlEarfcn%2Clte_ca_pcell_arfcn%2Clte_ca_pcell_band%2Clte_ca_scell_band%2Clte_ca_pcell_bandwidth%2Clte_ca_scell_info%2Clte_ca_scell_bandwidth%2Cwan_lte_ca%2Clte_pci%2CZ5g_CELL_ID%2CZ5g_SINR%2Ccell_id%2Cwan_lte_ca%2Clte_ca_pcell_band%2Clte_ca_pcell_bandwidth%2Clte_ca_scell_band%2Clte_ca_scell_bandwidth%2Clte_ca_pcell_arfcn%2Clte_ca_scell_arfcn%2Clte_multi_ca_scell_info%2Cwan_active_band%2Cnr5g_pci%2Cnr5g_action_band%2Cnr5g_cell_id%2Clte_snr%2Cecio%2Cwan_active_channel%2Cnr5g_action_channel%2Cngbr_cell_info%2Cmonthly_tx_bytes%2Cmonthly_rx_bytes%2Clte_pci%2Clte_pci_lock%2Clte_earfcn_lock%2Cwan_ipaddr%2Cwan_apn%2Cpm_sensor_mdm%2Cpm_modem_5g%2Cnr5g_pci%2Cnr5g_action_channel%2Cnr5g_action_band%2CZ5g_SINR%2CZ5g_rsrp%2Cwan_active_band%2Cwan_active_channel%2Cwan_lte_ca%2Clte_multi_ca_scell_info%2Ccell_id%2Cdns_mode%2Cprefer_dns_manual%2Cstandby_dns_manual%2Cnetwork_type%2Crmcc%2Crmnc%2Clte_rsrq%2Clte_rssi%2Clte_rsrp%2Clte_snr%2Cwan_lte_ca%2Clte_ca_pcell_band%2Clte_ca_pcell_bandwidth%2Clte_ca_scell_band%2Clte_ca_scell_bandwidth%2Clte_ca_pcell_arfcn%2Clte_ca_scell_arfcn%2Cwan_ipaddr%2Cstatic_wan_ipaddr%2Copms_wan_mode%2Copms_wan_auto_mode%2Cppp_status%2Cloginfo%2Crealtime_time%2Csignalbar&multi_data=1"
headers = {
"Host": self.ip,
"Referer": f"{self.referer}index.html",
"Cookie": cookie
}
response = requests.get(cmd_url, headers=headers, verify=False)
print(response.text)
router = ZTERouter("192.168.254.1", "admin", "admin")
router.get_router_info()
@pejotes
Copy link
Author

pejotes commented Apr 3, 2024

{
  "wa_inner_version": "STDMC8891.0.0B03",
  "cr_version": "",
  "network_type": "LTE",
  "rssi": "",
  "rscp": "",
  "rmcc": "260",
  "rmnc": "6",
  "enodeb_id": "340d",
  "lte_rsrq": "-12",
  "lte_rsrp": "-98",
  "Z5g_snr": "",
  "Z5g_rsrp": "",
  "ZCELLINFO_band": "",
  "Z5g_dlEarfcn": "",
  "lte_ca_pcell_arfcn": "",
  "lte_ca_pcell_band": "3",
  "lte_ca_scell_band": "7",
  "lte_ca_pcell_bandwidth": "15.0",
  "lte_ca_scell_info": "",
  "lte_ca_scell_bandwidth": "20.0",
  "wan_lte_ca": "ca_deactivated",
  "lte_pci": "6a",
  "Z5g_CELL_ID": "",
  "Z5g_SINR": "",
  "cell_id": "340d14",
  "lte_ca_scell_arfcn": "",
  "lte_multi_ca_scell_info": "1,106,1,7,3350,20.0",
  "wan_active_band": "LTE BAND 3",
  "nr5g_pci": "",
  "nr5g_action_band": "",
  "nr5g_cell_id": "",
  "lte_snr": "6.8",
  "ecio": "",
  "wan_active_channel": "1474",
  "nr5g_action_channel": "",
  "ngbr_cell_info": "1474,106,-11,-98,-66;1474,107,-14,-104,-81",
  "monthly_tx_bytes": "209866157",
  "monthly_rx_bytes": "160419394",
  "lte_pci_lock": "",
  "lte_earfcn_lock": "",
  "wan_ipaddr": "100.123.122.7",
  "wan_apn": "internet",
  "pm_sensor_mdm": "",
  "pm_modem_5g": "",
  "dns_mode": "auto",
  "prefer_dns_manual": "",
  "standby_dns_manual": "",
  "lte_rssi": "-68",
  "static_wan_ipaddr": "",
  "opms_wan_mode": "LTE_BRIDGE",
  "opms_wan_auto_mode": "AUTO_LTE_GATEWAY",
  "ppp_status": "ppp_connected",
  "loginfo": "ok",
  "realtime_time": "761170",
  "signalbar": "4"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment