Created
March 24, 2026 07:06
-
-
Save milankragujevic/4a8ebee4e9b1233514274e9bf81524f7 to your computer and use it in GitHub Desktop.
ZTE MC888 network reconnect script (with optional auto-reboot in case of Internet failure)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $ip = '192.168.0.1'; // MODEM IP HERE | |
| $password = 'admin'; // YOUR PASSWORD HERE | |
| $userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'; | |
| $logFile = 'zte_reconnect.log'; | |
| $cookieFile = tempnam(sys_get_temp_dir(), 'zte_full_reset_'); | |
| function logMessage($message, $logFile) { | |
| $timestamp = date('Y-m-d H:i:s'); | |
| $formattedMessage = "[$timestamp] $message\n"; | |
| echo $formattedMessage; | |
| file_put_contents($logFile, $formattedMessage, FILE_APPEND); | |
| } | |
| function pingHost($host) { | |
| $command = "ping -c 1 -W 2 " . escapeshellarg($host) . " > /dev/null 2>&1"; | |
| exec($command, $output, $result); | |
| return ($result === 0); | |
| } | |
| function makeRequest($url, $isPost = false, $postData = [], $cookieFile, $userAgent, $ip) { | |
| $ch = curl_init(); | |
| curl_setopt($ch, CURLOPT_URL, $url); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
| curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); | |
| curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile); | |
| curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile); | |
| curl_setopt($ch, CURLOPT_REFERER, "http://$ip/index.html"); | |
| curl_setopt($ch, CURLOPT_TIMEOUT, 15); | |
| if ($isPost) { | |
| curl_setopt($ch, CURLOPT_POST, true); | |
| curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData)); | |
| } | |
| $response = curl_exec($ch); | |
| curl_close($ch); | |
| return $response; | |
| } | |
| function getFreshAD($ip, $version, $cookieFile, $userAgent) { | |
| $rdRes = json_decode(makeRequest("http://$ip/goform/goform_get_cmd_process?isTest=false&cmd=RD", false, [], $cookieFile, $userAgent, $ip), true); | |
| $rd = $rdRes['RD'] ?? ''; | |
| if (!$rd) return null; | |
| $a = strtoupper(hash('sha256', $version)); | |
| return strtoupper(hash('sha256', $a . $rd)); | |
| } | |
| // check modem | |
| if (!pingHost($ip)) { | |
| logMessage("Error: Modem ($ip) is not reachable.", $logFile); | |
| exit(1); | |
| } | |
| // init | |
| logMessage("Radio module reconnection process started...", $logFile); | |
| $ldRes = json_decode(makeRequest("http://$ip/goform/goform_get_cmd_process?isTest=false&cmd=LD", false, [], $cookieFile, $userAgent, $ip), true); | |
| $ld = strtoupper($ldRes['LD'] ?? ''); | |
| $verRes = json_decode(makeRequest("http://$ip/goform/goform_get_cmd_process?isTest=false&cmd=wa_inner_version", false, [], $cookieFile, $userAgent, $ip), true); | |
| $version = $verRes['wa_inner_version'] ?? ''; | |
| if (!$ld || !$version) { | |
| logMessage("Error: Could not get LD and/or Version.", $logFile); | |
| exit(1); | |
| } | |
| // login | |
| $ad = getFreshAD($ip, $version, $cookieFile, $userAgent); | |
| $hashPassword = strtoupper(hash('sha256', $password)); | |
| $ztePass = strtoupper(hash('sha256', $hashPassword . $ld)); | |
| $loginResRaw = makeRequest("http://$ip/goform/goform_set_cmd_process", true, [ | |
| 'isTest' => 'false', | |
| 'goformId' => 'LOGIN', | |
| 'password' => $ztePass, | |
| 'AD' => $ad | |
| ], $cookieFile, $userAgent, $ip); | |
| $loginData = json_decode($loginResRaw, true); | |
| if (!isset($loginData['result']) || ($loginData['result'] !== '0' && $loginData['result'] !== 'success')) { | |
| logMessage("ERROR: Login failed.", $logFile); | |
| exit(1); | |
| } | |
| logMessage("Login success.", $logFile); | |
| // disconnect ppp data connection | |
| logMessage("Disconnecting network...", $logFile); | |
| $ad = getFreshAD($ip, $version, $cookieFile, $userAgent); | |
| makeRequest("http://$ip/goform/goform_set_cmd_process", true, [ | |
| 'isTest' => 'false', | |
| 'goformId' => 'DISCONNECT_NETWORK', | |
| 'AD' => $ad | |
| ], $cookieFile, $userAgent, $ip); | |
| sleep(3); | |
| // set to 3g only | |
| logMessage("Setting to 3G Only...", $logFile); | |
| $ad = getFreshAD($ip, $version, $cookieFile, $userAgent); | |
| makeRequest("http://$ip/goform/goform_set_cmd_process", true, [ | |
| 'isTest' => 'false', | |
| 'goformId' => 'SET_BEARER_PREFERENCE', | |
| 'BearerPreference' => 'Only_WCDMA', | |
| 'AD' => $ad | |
| ], $cookieFile, $userAgent, $ip); | |
| sleep(5); | |
| // set back to 5g auto | |
| logMessage("Setting back to 3G/4G/5G Auto...", $logFile); | |
| $ad = getFreshAD($ip, $version, $cookieFile, $userAgent); | |
| makeRequest("http://$ip/goform/goform_set_cmd_process", true, [ | |
| 'isTest' => 'false', | |
| 'goformId' => 'SET_BEARER_PREFERENCE', | |
| 'BearerPreference' => 'WL_AND_5G', | |
| 'AD' => $ad | |
| ], $cookieFile, $userAgent, $ip); | |
| sleep(15); | |
| // reconnect ppp data | |
| logMessage("Connecting to network...", $logFile); | |
| $ad = getFreshAD($ip, $version, $cookieFile, $userAgent); | |
| makeRequest("http://$ip/goform/goform_set_cmd_process", true, [ | |
| 'isTest' => 'false', | |
| 'goformId' => 'CONNECT_NETWORK', | |
| 'AD' => $ad | |
| ], $cookieFile, $userAgent, $ip); | |
| logMessage("Waiting 60s for network to connect...", $logFile); | |
| sleep(60); | |
| // check and reboot if needed | |
| $ping1 = pingHost('1.1.1.1'); | |
| $ping2 = pingHost('8.8.8.8'); | |
| if ($ping1 || $ping2) { | |
| logMessage("Check successful. Internet is available.", $logFile); | |
| } else { | |
| logMessage("INTERNET DOWN: Performing modem reboot...", $logFile); | |
| $ad = getFreshAD($ip, $version, $cookieFile, $userAgent); | |
| makeRequest("http://$ip/goform/goform_set_cmd_process", true, [ | |
| 'isTest' => 'false', | |
| 'goformId' => 'REBOOT_DEVICE', | |
| 'AD' => $ad | |
| ], $cookieFile, $userAgent, $ip); | |
| logMessage("Reboot command sent. ", $logFile); | |
| } | |
| logMessage("Process finished.", $logFile); | |
| if (file_exists($cookieFile)) unlink($cookieFile); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment