Why does NetworkChange.NetworkAddressChanged keep getting raised?

102 Views Asked by At

I am running .NET 7 on Linux. I tried get network change information with the following code, but I keep getting the event, even though the computer is constantly on, and it is a wired Ethernet. The addresses seem the same. Then, why is "network address change" keep happening?

Output

15:59:47:    lo is Up. Desc:127.0.0.1
15:59:47:    enp9s0 is Up. Desc:192.168.1.211
16:00:17:    lo is Up. Desc:127.0.0.1
16:00:17:    enp9s0 is Up. Desc:192.168.1.211
16:00:47:    lo is Up. Desc:127.0.0.1
16:00:47:    enp9s0 is Up. Desc:192.168.1.211
16:01:17:    lo is Up. Desc:127.0.0.1
16:01:17:    enp9s0 is Up. Desc:192.168.1.211
16:01:47:    lo is Up. Desc:127.0.0.1
16:01:47:    enp9s0 is Up. Desc:192.168.1.211
16:02:17:    lo is Up. Desc:127.0.0.1
16:02:17:    enp9s0 is Up. Desc:192.168.1.211
16:02:47:    lo is Up. Desc:127.0.0.1
16:02:47:    enp9s0 is Up. Desc:192.168.1.211

Code

System.Net.NetworkInformation.NetworkChange.NetworkAddressChanged += (sender, eventArgs) =>
{
    NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
    foreach(NetworkInterface n in adapters)
    {
        PrintLog($"   {n.Name} is {n.OperationalStatus}. Desc:{n.GetIPProperties().UnicastAddresses.First().Address.ToString()}");
    }
};
0

There are 0 best solutions below