Capture network activity on a local/private network

Low-level socket access used to require a library like GitHub - msantos/procket: Erlang interface to low level socket operations. A sample snippet for network packet capture can be found in the README.

Recent OTP versions introduced the experimental socket module, which offers a similar feature set as ‘procket’, so it may now be possible to capture packets without any dependencies.

You do have to think about how to gain the necessary permissions: running your application as root is definitely not a good idea. You may be able to give the BEAM executable the necessary permissions with setcap (see also this thread). The ‘sprocket’ library actually solves this issue with a small SUID helper.

Edit: you may also want to check out the other projects by the author of ‘procket’: some deal specifically with packet capture and BPF filters.

3 Likes