Skip to content

Instantly share code, notes, and snippets.

@dhoepfl
Created October 27, 2022 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhoepfl/051480752441659b34ba5a9c4166ae60 to your computer and use it in GitHub Desktop.
Save dhoepfl/051480752441659b34ba5a9c4166ae60 to your computer and use it in GitHub Desktop.
Dumps the information the networksetup tool provides for all locations.
#! /bin/bash
RESULT_FOLDER="Network Setups"
rm -fr "$RESULT_FOLDER"
function perform()
{
OUT="$1/$2.txt"
CMD="$2"
shift; shift
networksetup "-$CMD" "$@" >"$OUT"
}
CURRENT="$(networksetup -getcurrentlocation)"
trap "networksetup -switchtolocation \"$CURRENT\" >/dev/null" EXIT
networksetup -listlocations | while read LOCATION ; do
echo "$LOCATION"
LOCATION_FOLDER="$(echo "$LOCATION" | sed -e 's/[^-()_ a-zA-Z 0-9]//g')"
mkdir -p "$RESULT_FOLDER/$LOCATION_FOLDER"
echo "LOCATION: $LOCATION" >"$RESULT_FOLDER/$LOCATION_FOLDER/location.txt"
networksetup -switchtolocation "$LOCATION" >>"$RESULT_FOLDER/$LOCATION_FOLDER/location.txt"
perform "$RESULT_FOLDER/$LOCATION_FOLDER" getcomputername
perform "$RESULT_FOLDER/$LOCATION_FOLDER" listnetworkserviceorder
perform "$RESULT_FOLDER/$LOCATION_FOLDER" listallhardwareports
perform "$RESULT_FOLDER/$LOCATION_FOLDER" listVLANs
perform "$RESULT_FOLDER/$LOCATION_FOLDER" listpppoeservices
perform "$RESULT_FOLDER/$LOCATION_FOLDER" listalluserprofiles
perform "$RESULT_FOLDER/$LOCATION_FOLDER" listdevicesthatsupportVLAN
perform "$RESULT_FOLDER/$LOCATION_FOLDER" listBonds
networksetup -listBonds | grep '^interface name' | sed -e 's/.*: //' | while read BOND ; do
BOND_FOLDER="$(echo "$BOND" | sed -e 's/[^-()_ a-zA-Z 0-9]//g')"
mkdir -p "$RESULT_FOLDER/$LOCATION_FOLDER/Bonds/$BOND_FOLDER"
perform "$RESULT_FOLDER/$LOCATION_FOLDER/Bonds/$BOND_FOLDER" showBondStatus "$BOND"
done
perform "$RESULT_FOLDER/$LOCATION_FOLDER" listallnetworkservices
networksetup -listallnetworkservices | grep -v "denotes that a network service is disabled" | while read NETWORKSERVICE ; do
SERVICE_FOLDER="$(echo "$NETWORKSERVICE" | sed -e 's/[^-()_ a-zA-Z 0-9]//g')"
mkdir -p "$RESULT_FOLDER/$LOCATION_FOLDER/Services/$SERVICE_FOLDER"
perform "$RESULT_FOLDER/$LOCATION_FOLDER/Services/$SERVICE_FOLDER" listloginprofiles "$NETWORKSERVICE"
perform "$RESULT_FOLDER/$LOCATION_FOLDER/Services/$SERVICE_FOLDER" getinfo "$NETWORKSERVICE"
perform "$RESULT_FOLDER/$LOCATION_FOLDER/Services/$SERVICE_FOLDER" getnetworkserviceenabled "$NETWORKSERVICE"
perform "$RESULT_FOLDER/$LOCATION_FOLDER/Services/$SERVICE_FOLDER" getadditionalroutes "$NETWORKSERVICE"
perform "$RESULT_FOLDER/$LOCATION_FOLDER/Services/$SERVICE_FOLDER" getv6additionalroutes "$NETWORKSERVICE"
perform "$RESULT_FOLDER/$LOCATION_FOLDER/Services/$SERVICE_FOLDER" getdnsservers "$NETWORKSERVICE"
perform "$RESULT_FOLDER/$LOCATION_FOLDER/Services/$SERVICE_FOLDER" getsearchdomains "$NETWORKSERVICE"
perform "$RESULT_FOLDER/$LOCATION_FOLDER/Services/$SERVICE_FOLDER" getftpproxy "$NETWORKSERVICE"
perform "$RESULT_FOLDER/$LOCATION_FOLDER/Services/$SERVICE_FOLDER" getwebproxy "$NETWORKSERVICE"
perform "$RESULT_FOLDER/$LOCATION_FOLDER/Services/$SERVICE_FOLDER" getsecurewebproxy "$NETWORKSERVICE"
perform "$RESULT_FOLDER/$LOCATION_FOLDER/Services/$SERVICE_FOLDER" getstreamingproxy "$NETWORKSERVICE"
perform "$RESULT_FOLDER/$LOCATION_FOLDER/Services/$SERVICE_FOLDER" getgopherproxy "$NETWORKSERVICE"
perform "$RESULT_FOLDER/$LOCATION_FOLDER/Services/$SERVICE_FOLDER" getsocksfirewallproxy "$NETWORKSERVICE"
perform "$RESULT_FOLDER/$LOCATION_FOLDER/Services/$SERVICE_FOLDER" getproxybypassdomains "$NETWORKSERVICE"
perform "$RESULT_FOLDER/$LOCATION_FOLDER/Services/$SERVICE_FOLDER" getproxyautodiscovery "$NETWORKSERVICE"
perform "$RESULT_FOLDER/$LOCATION_FOLDER/Services/$SERVICE_FOLDER" getpassiveftp "$NETWORKSERVICE"
networksetup -listnetworkserviceorder | grep '^.H' | sort -u | while read LINE; do
PORT="$(echo "$LINE" | sed -e 's/^.Hardware Port: //' -e 's/, Device: [^ ]*.$//')"
DEVICE="$(echo "$LINE" | sed -e 's/^.Hardware Port: .*, Device: //' -e 's/.$//')"
mkdir -p "$RESULT_FOLDER/$LOCATION_FOLDER/Devices/$DEVICE"
perform "$RESULT_FOLDER/$LOCATION_FOLDER/Devices/$DEVICE" getairportnetwork "$DEVICE"
perform "$RESULT_FOLDER/$LOCATION_FOLDER/Devices/$DEVICE" getairportpower "$DEVICE"
perform "$RESULT_FOLDER/$LOCATION_FOLDER/Devices/$DEVICE" listpreferredwirelessnetworks "$DEVICE"
perform "$RESULT_FOLDER/$LOCATION_FOLDER/Devices/$DEVICE" getMTU "$DEVICE"
perform "$RESULT_FOLDER/$LOCATION_FOLDER/Devices/$DEVICE" getmedia "$DEVICE"
PORT_FOLDER="$(echo "$PORT" | sed -e 's/[^-()_ a-zA-Z 0-9]//g')"
mkdir -p "$RESULT_FOLDER/$LOCATION_FOLDER/Port/$PORT_FOLDER"
perform "$RESULT_FOLDER/$LOCATION_FOLDER/Port/$PORT_FOLDER" getMTU "$PORT"
perform "$RESULT_FOLDER/$LOCATION_FOLDER/Port/$PORT_FOLDER" getmedia "$PORT"
done
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment