Skip to content

Instantly share code, notes, and snippets.

@adiberr
Last active March 31, 2024 23:03
Show Gist options
  • Select an option

  • Save adiberr/2ee1a8d6518625b348ddb1ba9bea6671 to your computer and use it in GitHub Desktop.

Select an option

Save adiberr/2ee1a8d6518625b348ddb1ba9bea6671 to your computer and use it in GitHub Desktop.
Oneliner command to parse UFW logs, useful for abuse blocking and reporting

Extract the source ip address and destination port :

sed -n 's/^.*SRC=\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\).*DPT=\([0-9]\+\).*$/\1 \2/p' <<< $(sudo cat /var/log/ufw.log) \
| uniq -c \
| sort \
| column -t

Example (details omitted for simplicity):

...
[..] SRC=192.168.100.119 DST=192.168.100.1 LEN=40 TOS=0x00 PREC=0x00 TTL=239 ID=1 PROTO=TCP SPT=23 [..]
...
[..] SRC=192.168.100.120 DST=192.168.100.1 LEN=40 TOS=0x00 PREC=0x00 TTL=239 ID=2 PROTO=TCP SPT=23 [..]

Result :

7   192.168.100.119   23
10  192.168.100.120   23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment