Mac OSX one-liners to get specific IP Info
I needed to allow users to print very specific networking information with ease.
A typical user doesn’t want to decipher all of the extra info and steps an ifconfig or similar command can bring.
While building this script, I ended up with quite a few one-liners that could be useful for every day admin tasks
Print ONLY IP Addressipconfig getifaddr en0
print ONLY Gatewayroute -n get default | awk '/gateway: / {print $2;} '
print ONLY Network Mask for Wi-Fi connectionnetworksetup -getinfo "Wi-Fi" | awk '/Subnet mask:/ {print $3;} '
print ONLY Network Addressip=$(ipconfig getifaddr en0) && nm=$(networksetup -getinfo "Wi-Fi" | awk '/Subnet mask:/ {print $3;} ') && IFS=. read -r i1 i2 i3 i4 <<< $ip="" 038="" ifs="." read="" -r="" m1="" m2="" m3="" m4="" <<<="" $nm="" printf="" d.="" d\n="" $="" i1="" $i2="" i3="" i4="" <="" code="">
Print all DNS servers on one linecat /etc/resolv.conf | awk '/nameserver / {print $2;} ' | tr "\n" " "
The post Mac OSX one-liners to get specific IP Info first appeared on j0e.us.