2

I am trying to write a piece of go code that will trigger an expensive function. Right now the expensive function is triggered in an interval of a five seconds.

The thing is, that it only needs to be triggered, only if the state of connections in NetworkManager of linux has changed. For example from connecting to router x (the coffeeshop wifi), it connected to router y (my phones hotspot).

Is there a way to receive an event (similar to how one can get notified about file system change using inotify) for network connection changes?

Amirography
  • 21
  • 1
  • 4
  • 1
    Could you elaborate more about what you mean by "only if the state of connections in NetworkManager of linux has changed." You mean something like `Wireless Enabled`? – Ali-Ibrahim Sep 04 '22 at 16:53
  • This is probably a bit of a sledge hammer approach, and something I've only vaguely heard about so I cannot help, but you _could try_ using syscalls to [strace](https://presearch.com/search?q=strace+network+connection) the program that handles it, or use EBP filtering to monitor your networking. Liz Rice gave some presentations on both which you could find on youtube. Probably libraries out there for it. – kendfss Sep 04 '22 at 19:04
  • @C137 i added an example. What i mean can be simply change from connecting to this wifi router, to another one. – Amirography Sep 04 '22 at 19:12
  • I'm not sure if this is what you're looking for, but it might be useful: https://stackoverflow.com/a/2353441/131930 – Jeremy Friesner Sep 04 '22 at 19:15
  • @JeremyFriesner yes! I was looking for that kind of solution! Thanks! – Amirography Sep 04 '22 at 19:27
  • @JamesRisner probably, unless there is something specific to NetworkManager in this question. – Jeremy Friesner Sep 07 '22 at 00:05

0 Answers0