static void Main(string[] args) { var ip = System.Net.IPAddress.Parse("10.1.0.200"); var netMon = new NetworkMonitor(ip); netMon.OnError += OnError; netMon.Begin(); while (true) { } }
/// <summary> /// Creates a NetworkMonitor instance for each /// valid network interface. /// </summary> /// <returns>Returns an array of NetworkMonitor instances.</returns> public static NetworkMonitor[] BindInterfaces() { // Get all up and running interfaces. var validInterfaces = GetInterfaces(); // List for storing NetworkMonitor objects. var monitors = new List <NetworkMonitor>(); foreach (var netInterface in validInterfaces) { var ipConfig = netInterface.GetIPProperties(); foreach (var uni in ipConfig.UnicastAddresses) { if (uni.Address.AddressFamily == AddressFamily.InterNetwork) { var mon = new NetworkMonitor(uni.Address); monitors.Add(mon); } /* Check if IPv4. */ } /* Loop through unicast addresses. */ } /* Loop through all valid interfaces. */ return(monitors.ToArray()); }