From 379b149a48686fdcfbe5468aff5e2f572ffb842d Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Wed, 6 Nov 2024 14:27:03 +0100 Subject: [PATCH] added restartinterface script & renamed tbind w/o suffix --- scripts/rinterface | 18 ++++++++++++++++++ scripts/{tbind.sh => tbind} | 0 2 files changed, 18 insertions(+) create mode 100644 scripts/rinterface rename scripts/{tbind.sh => tbind} (100%) diff --git a/scripts/rinterface b/scripts/rinterface new file mode 100644 index 0000000..10f373a --- /dev/null +++ b/scripts/rinterface @@ -0,0 +1,18 @@ +#!/bin/sh + +# Loop through each hardware port and device pair +networksetup -listallhardwareports | awk ' +/^Hardware Port:/ {interface_name=$3; for(i=4;i<=NF;i++){interface_name=interface_name" "$i}} +/^Device:/ {print interface_name, $2}' | \ +while read interface_name interface; do + # Get the IP address for the current interface + ip=$(ipconfig getifaddr "$interface" 2>/dev/null) + + if [ -n "$ip" ]; then + echo "restarting interface $interface ($interface_name)" + + # Disable and enable network service by hardware port name + networksetup -setnetworkserviceenabled "$interface_name" off + networksetup -setnetworkserviceenabled "$interface_name" on + fi +done diff --git a/scripts/tbind.sh b/scripts/tbind similarity index 100% rename from scripts/tbind.sh rename to scripts/tbind