NetworkChange.NetworkAddressChanged Event


Occurs when the IP address of a network interface changes.

Namespace:   System.Net.NetworkInformation
Assembly:  System (in System.dll)

Public Shared Event NetworkAddressChanged As NetworkAddressChangedEventHandler

The NetworkChange class raises NetworkAddressChanged events when the address of a network interface, also called a network card or adapter, changes.

To have a NetworkChange object call an event-handling method when a NetworkAddressChanged event occurs, you must associate the method with a NetworkAddressChangedEventHandler delegate, and add this delegate to this event.

The NetworkAddressChanged event is supported on Windows 2000 and later.

The following code example listens for address changes and displays the status of network interfaces when a NetworkAddressChanged event occurs.

Imports System
Imports System.Net
Imports System.Net.NetworkInformation

Public Class NetworkingExample
    Public Shared Sub Main()
        AddHandler NetworkChange.NetworkAddressChanged, AddressOf AddressChangedCallback
        Console.WriteLine("Listening for address changes. Press any key to exit.")
    End Sub 'Main
    Private Shared Sub AddressChangedCallback(ByVal sender As Object, ByVal e As EventArgs)

        Dim adapters As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()
        Dim n As NetworkInterface
        For Each n In adapters
            Console.WriteLine("   {0} is {1}", n.Name, n.OperationalStatus)
        Next n
    End Sub
End Class

Universal Windows Platform
Available since 8
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Available since 3.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top