AutomoxAutomox

Worklet: Check Internet Connection Speed Mac OS

Landon-Automox
September 25, 2023 at 9:48 pm UTC
#Worklets

I wrote this macOS bash Worklet with the help of Otto AI to check the speed of an internet connection on macOS devices.

It’s my entry into the Just Script It challenge! 

Evaluation

bash4 lines
# This Worklet runs a speed test on Mac OS devices using the networkQuality command. 
# This command was included starting with Mac OS Monterrey.
#Exit non-compliant to run remediation script
exit 1

 

Remediation

bash38 lines
# ======================
# Otto AI Generated Code
# ======================

#intro message: 
clear
echo "Checking Network Quality......"

# s allows for sequential testing, which tends to yield more accurate results
# c is computer readable output
# networkQuality available starting with Monterrey 

output=$(networkQuality -sc)

# Remove leading/trailing whitespace and curly braces
output=${output#*{}
output=${output%{}*}

# Extract the values using pattern matching
uplink_capacity=$(grep -o '"ul_throughput" : [0-9]*' <<< "$output" | awk '{print $NF}')
uplink_capacity=$(($uplink_capacity/1000000))
downlink_capacity=$(grep -o '"dl_throughput" : [0-9]*' <<< "$output" | awk '{print $NF}')
downlink_capacity=$(($downlink_capacity/1000000))
os_version=$(grep -o '"os_version" : "[^"]*"' <<< "$output" | cut -d'"' -f4)
interface=$(grep -o '"interface_name" : "[^"]*"' <<< "$output" | cut -d'"' -f4)

#Get info on whether connection is WiFi or Ethernet
network_type=$(networksetup -listnetworkserviceorder | grep -C1 $interface)
connection_type=$(echo "$network_type" | awk -F 'Hardware Port: ' '/Hardware Port:/{print $2}' | cut -d',' -f1)

clear

#Output the Info
echo "Download Speed: $downlink_capacity Mbps"
echo "Upload Speed: $uplink_capacity Mbps"
echo "OS Version: $os_version"
echo "Interface: $interface"
echo "Connection Type: $connection_type"

 

This discussion is archived and closed to replies. Continue it in the Automox Community Slack.

Discuss on Slack

Replies (1)

SophiaAXSeptember 27, 2023
#1

Awesome work on this, Landon! Thanks for sharing :)