Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'Another Take' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Another Take
Authored by: joelbruner on Mar 09, '10 01:21:10PM
Here's another take on this, it checks to see if en0 and en1 are using the same DHCP server, a surer way to tell if you are duplicating a network connection. Then gives user time to unplug the cable, this way they can turn on wireless and maintain connection so Finder won't freak out. Also Geeklog or whatever blog system this is seems to want to mangle the \n newline in display dialog for some reason...
scriptName=$(basename $0)

function getDHCPservers { en0=$(ipconfig getpacket en0 | grep server_identifier | awk {'print $3'}) en1=$(ipconfig getpacket en1 | grep server_identifier | awk {'print $3'}) }
function sendlog { logger -t "$scriptName [$$]" ${1} }
#just in case the values aren't flushed after network transition sendlog "Network Transition Detected" #give it a moment to get values sleep 5 getDHCPservers;
if [ -z "$en0" -o -z "$en1" ]; then sendlog "No DHCP Server Redundancy: en0=$en0 en1=$en1" exit; fi
if [ "$en0" == "$en1" ]; then sendlog "DHCP Server Redundancy: en0=$en0 en1=$en1" sendlog "Waiting 30 Seconds for User to Disconnect Ethernet" sleep 30 getDHCPservers;
#check again if [ "$en0" == "$en1" ]; then sendlog "Duplicate DHCP Server persist: en0=$en0 en1=$en1" sudo networksetup -setairportpower Airport off sendlog "Airport Turned Off" open /System/Library/CoreServices/Menu\ Extras/ osascript <<-EOF tell application "Finder" display dialog "Duplicate Net Connections Found&#92;nAirport Turned Off" buttons { "OK" } with icon 2 giving up after 15 end tell EOF fi else sendlog "No DHCP Server Redundancy" fi

[ Reply to This | # ]