The easiest way is probably to write a loop to monitor / proc / net / tcp or / proc / net / tcp6. However, it is too inefficient, since I need to get a notification almost immediately. The closest I looked at is inotify, which can provide callbacks in I / O events in any files. The problem is that procfs is not a regular file system and inotify does not support it (at least not for / proc / net / tcp and / proc / net / tcp6).
In addition, I do not want the program to have root privileges to implement this.
EDIT: I removed the user space connection requirement. Also, I hope there is built-in kernel support, such as inotify, that can do this. This may be too intrusive in my case to manipulate iptables.
Anyone have an idea? Thank you !!
source
share