This article explains a bit more what's going on in the code.
Simple sniffer written on Elixir using sockets.
Requires OTP version 22+
Run iex:
iex sniffer.ex
Start the sniffer:
> Sniffer.start_link([if_name: "wlp1s0", promiscuous: true])
> Sniffer.start_link([if_name: "wlp1s0"])
> Sniffer.start_link([])
Make sure you have permissions to parse raw packets and enable promiscuous mode.
It may require you to use sudo
or set Linux capabilities:
setcap cap_net_raw,cap_net_admin=ep ERLANG_PATH/erts-VERSION/bin/beam.smp
When promiscuous mode is enabled by the sniffer it is not set back when application clesed. Make sure you turn it off manually:
ip link set wlp1s0 promisc off