OnionUI / Onion

OS overhaul for Miyoo Mini and Mini+
https://onionui.github.io
GNU General Public License v3.0
3.32k stars 207 forks source link

Add basic network diag script #1583

Open XK9274 opened 4 months ago

XK9274 commented 4 months ago

Summary

A network check suite, quite basic for now but will help with debugging network issues as it grows. Designed to be called from the Tweaks -> Advanced -> Diagnostics menu however, can be called on the cmdline.

Will address: https://github.com/OnionUI/Onion/issues/1317 when complete

Waiting on Schmurtz to come back to check this over, we agreed on spidering for checking websites but this script can do almost all of it, just need to check the baked in domains/IP addresses against users who have issues in blocked regions (mostly China)

Examples

Through tweaks

When running as standalone through tweaks it will use the diagnostics framework, the script will generate an output similar to the below, which will be pushed through the exporter to an archive called log_export.7z on the SD root, containing some log files but most importantly these check results:


2024-05-13 21:50:44 - ================================ Hardware and config checks ================================
2024-05-13 21:50:44 - Check successful: Found 3 USB devices connected.
2024-05-13 21:50:44 - 8188fu driver is loaded and active.
2024-05-13 21:50:44 - WiFi is enabled, proceeding with network checks.
2024-05-13 21:50:44 - Active network interfaces found: wlan0
2024-05-13 21:50:44 - DNS Resolvers found: 192.168.1.254
2024-05-13 21:50:44 - Ping to DNS resolver 192.168.1.254 successful.
2024-05-13 21:50:44 - Network check complete for wlan0: IP 192.168.1.215, Subnet Mask 255.255.255.0, Gateway 192.168.1.254, DNS Resolvers: 192.168.1.254

2024-05-13 21:50:44 - ================================ Network Ping Tests ================================
2024-05-13 21:50:44 - Starting ping test for Google DNS: 8.8.8.8
2024-05-13 21:50:44 - Ping to 8.8.8.8 (Google DNS) successful.

2024-05-13 21:50:44 - Starting ping test for Cloudflare DNS: 1.1.1.1
2024-05-13 21:50:44 - Ping to 1.1.1.1 (Cloudflare DNS) successful.

2024-05-13 21:50:44 - Starting ping test for OpenDNS: 208.67.222.222
2024-05-13 21:50:44 - Ping to 208.67.222.222 (OpenDNS) successful.

2024-05-13 21:50:44 - ================================ Service and Game Site Checks ================================
2024-05-13 21:50:44 - Checking website availability: https://github.com
2024-05-13 21:50:45 - Website https://github.com is up.

2024-05-13 21:50:45 - Checking website availability: https://www.baidu.com
2024-05-13 21:50:47 - Website https://www.baidu.com is up.

2024-05-13 21:50:47 - Checking website availability: https://www.naver.com
2024-05-13 21:50:49 - Website https://www.naver.com is up.

2024-05-13 21:50:49 - Checking website availability: https://www.uol.com.br
2024-05-13 21:50:50 - Website https://www.uol.com.br is up.

2024-05-13 21:50:50 - Checking website availability: https://www.timesofindia.indiatimes.com
2024-05-13 21:50:51 - Website https://www.timesofindia.indiatimes.com is up.

2024-05-13 21:50:51 - Checking website availability: http://lobby.libretro.com/
2024-05-13 21:50:52 - Website http://lobby.libretro.com/ is up.

2024-05-13 21:50:52 - Checking website availability: https://www.lexaloffle.com/bbs/cpost_lister3.php?cat=7
2024-05-13 21:50:53 - Website https://www.lexaloffle.com/bbs/cpost_lister3.php?cat=7 is up.

2024-05-13 21:50:53 - ================================ Download Tests ================================
2024-05-13 21:50:53 - Testing download from: https://raw.githubusercontent.com/OnionUI/Themes/main/release/M%20by%20tenlevels.zip
2024-05-13 21:50:53 - Download test for https://raw.githubusercontent.com/OnionUI/Themes/main/release/M%20by%20tenlevels.zip was successful. Status code: 200

2024-05-13 21:50:53 - Testing download from: https://github.com/OnionUI/Ports-Collection/releases/latest/download/Sonic.Mania.7z
2024-05-13 21:50:54 - Download test for https://github.com/OnionUI/Ports-Collection/releases/latest/download/Sonic.Mania.7z was successful. Status code: 200

2024-05-13 21:50:54 - Testing download from: https://www.lexaloffle.com/bbs/cpost_lister3.php?cat=7
2024-05-13 21:50:54 - Download test for https://www.lexaloffle.com/bbs/cpost_lister3.php?cat=7 was successful. Status code: 200

2024-05-13 21:50:54 - ================================ RetroAchievements API Check ================================
2024-05-13 21:50:54 - Checking RetroAchievements API availability
2024-05-13 21:50:55 - API check was successful, returned 401 unauthorized. Status code: 401

2024-05-13 21:50:55 - ================================ Firmware DNS Check ================================
2024-05-13 21:50:55 - Firmware supports DNS, testing...

2024-05-13 21:50:55 - DNS resolution test for google.co.uk successful.

2024-05-13 21:50:55 - ================================ System Network Configuration ================================
2024-05-13 21:50:55 - Collecting network configuration information
2024-05-13 21:50:55 - ================================ Summary of Network Checks ================================
2024-05-13 21:50:55 - Ping Test Results: 3 successful out of 3 attempts.
2024-05-13 21:50:55 - Website Availability: 7 successful out of 7 checks.
2024-05-13 21:50:55 - Download Test Results: 3 successful out of 3 attempts.
2024-05-13 21:50:55 - Ping replies from all DNS providers - OK
2024-05-13 21:50:55 - Website checks - All sites are reachable
2024-05-13 21:50:55 - Download tests - All downloads successful
2024-05-13 21:50:55 - Executing exporter utility.
(util_exporter) 2024-05-13 21:50:55: Exporting and archiving logs
(util_exporter) 2024-05-13 21:50:55: Moving runtime logs
(util_exporter) 2024-05-13 21:50:56: Exported to: /mnt/SDCARD/log_export.7z
2024-05-13 21:50:56 - Network checks complete.

On cmdline

It can also be called on cmdline to expose the checks to other processes, returning a 0 on success and non-zero on failure:

./util_netcheck.sh perform_ping 8.8.8.8 "Google DNS" # Quick ping, when on cmdline the second arg can be anything
./util_netcheck.sh check_website https://github.com # Spider a website
./util_netcheck.sh test_download "https://raw.githubusercontent.com/OnionUI/Themes/main/release/M%20by%20tenlevels.zip" # Test run a download
./util_netcheck.sh check_firmware_for_dns_issue # Check if the device has a firmware capable of DNS, then test DNS 
./util_netcheck.sh check_network_complete # Checks if the current network is "complete" (IP/Subnet/Gateway/DNS all valid)
./util_netcheck.sh check_retroachievements_api # Checks if the Cheevos API replies to a failed request as expected
/mnt/SDCARD/.tmp_update/script/diagnostics # ./util_netcheck.sh check_website https://github.com
2024-05-13 20:53:59 - Active network interfaces found: wlan0
2024-05-13 20:53:59 - Proceeding, valid adaptor found
2024-05-13 20:53:59 - Checking website availability: https://github.com
2024-05-13 20:54:00 - Website https://github.com is up.

/mnt/SDCARD/.tmp_update/script/diagnostics # echo $?
0
/mnt/SDCARD/.tmp_update/script/diagnostics # ./util_netcheck.sh check_website https://github2222.com
2024-05-13 20:54:39 - Active network interfaces found: wlan0
2024-05-13 20:54:39 - Proceeding, valid adaptor found
2024-05-13 20:54:39 - Checking website availability: https://github2222.com
Failed to establish connection
2024-05-13 20:54:39 - Website https://github2222.com is down.

/mnt/SDCARD/.tmp_update/script/diagnostics # echo $?
1