WizardKit/scripts/wk/hw/network.py

54 lines
1.2 KiB
Python

"""WizardKit: Network test functions"""
# vim: sts=2 sw=2 ts=2
import logging
from wk.net import (
connected_to_private_network,
ping,
show_valid_addresses,
speedtest,
)
from wk.ui import cli as ui
# STATIC VARIABLES
LOG = logging.getLogger(__name__)
# Functions
def network_test() -> None:
"""Run network tests."""
LOG.info('Network Test')
try_and_print = ui.TryAndPrint()
result = try_and_print.run(
message='Network connection...',
function=connected_to_private_network,
msg_good='OK',
raise_on_error=True,
)
# Bail if not connected
if result['Failed']:
ui.print_warning('Please connect to a network and try again')
ui.pause('Press Enter to return to main menu...')
return
# Show IP address(es)
show_valid_addresses()
# Ping tests
try_and_print.run(
'Internet connection...', ping, msg_good='OK', addr='8.8.8.8')
try_and_print.run(
'DNS resolution...', ping, msg_good='OK', addr='google.com')
# Speedtest
try_and_print.run('Speedtest...', speedtest)
# Done
ui.pause('Press Enter to return to main menu...')
if __name__ == '__main__':
print("This file is not meant to be called directly.")