IT notes

get the Primary IP

To get the primary IP in Linux: ip route get 1 | awk '{print $NF;exit}' In awk NF return the number of fields and by suffixing it with $ is like doing print $7 In macOS, to list all your interfaces: networksetup -listallhardwareports If want to get the IP assigned to the Wi-FI: ipconfig getifaddr $(networksetup -listallhardwareports | awk '/Hardware Port: Wi-Fi/{getline; print $2}')