How to detect network change (unplugging/plugging cable)?

Solution 1:

This project in Github does what you are looking for - look in there to see how he is doing it. https://github.com/paulbhart/toggleairport

He watches these three files to determine that the network status has changed:

  • /private/var/run/resolv.conf
  • /Library/Preferences/SystemConfiguration/NetworkInterfaces.plist
  • /Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist

The purpose of his project is to turn off WiFi if the LAN is connected, and turn it back on again if the LAN is disconnected.