Created
February 11, 2025 19:19
-
-
Save james-see/2845e15a11c98afe36e785fb7fd0e2ac to your computer and use it in GitHub Desktop.
get wifi connection info to help with connectivity issues
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
add a line or similar to
~/.zshrc
like this:alias wifime='~/scripts/get_wifi_info.sh'