0

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()}");
    }
};
Damn Vegetables
  • 11,484
  • 13
  • 80
  • 135
  • Probably this is due to some dhcp settings (IP-address leasing feature imho). I ran your code for night at my Manjaro Linux - this happens once per 5 hours. – Ryan May 08 '23 at 02:10

0 Answers0