macOS has a built-in, simple bandwidth analysis tool that tests access to Apple’s CDN to check upload and download speeds. The /usr/bin/networkQuality command can be run with no flags and will produce output that appears as follows:
/usr/bin/networkQuality
==== SUMMARY ====
Uplink capacity: 7.259 Mbps
Downlink capacity: 157.597 Mbps
Responsiveness: Low (118 RPM)
Idle Latency: 56.333 milliseconds
networkQuality can also bind to a specific port, useful in testing devices that might have multiple interfaces. To do that, use the -I flag:
networkQuality -I en0
Finally, to parse the output to just see the floating point result of a given field, we can pip it into awk, so for upload we’d use the following (or swap Uplink for Downlink to get that):
networkQuality | grep Uplink | awk '{print $3}'