Skip to content

Instantly share code, notes, and snippets.

@james-see
Created February 11, 2025 19:19
Show Gist options
  • Save james-see/2845e15a11c98afe36e785fb7fd0e2ac to your computer and use it in GitHub Desktop.
Save james-see/2845e15a11c98afe36e785fb7fd0e2ac to your computer and use it in GitHub Desktop.
get wifi connection info to help with connectivity issues
#!/bin/bash
# Get the current Wi-Fi interface
wifi_interface=$(networksetup -listallhardwareports | awk '/Wi-Fi/{getline; print $2}')
# Get the current connected Wi-Fi network details
wifi_network=$(networksetup -getairportnetwork $wifi_interface | awk -F": " '{print $2}')
# Get the IP address
ip_address=$(ipconfig getifaddr $wifi_interface)
# Get the router (gateway)
router=$(netstat -rn | grep default | grep $wifi_interface | awk '{print $2}')
# Get the DNS servers using scutil and remove duplicates
dns_servers=$(scutil --dns | grep 'nameserver\[[0-9]*\]' | awk '{print $3}' | sort | uniq)
echo "Current Wi-Fi Network: $wifi_network"
echo "IP Address: $ip_address"
echo "Router: $router"
echo "DNS Servers:"
for dns in $dns_servers; do
echo " $dns"
done
@james-see
Copy link
Author

add a line or similar to ~/.zshrc like this:

alias wifime='~/scripts/get_wifi_info.sh'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment