Skip to content

Instantly share code, notes, and snippets.

@rlei
Last active March 7, 2020 13:08
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rlei/7005b8ded081a0e0cc971570646a385e to your computer and use it in GitHub Desktop.
Save rlei/7005b8ded081a0e0cc971570646a385e to your computer and use it in GitHub Desktop.
Generate CSV of country/city/geo location/ISP information of the IPs banned by sshguard. Requires jq (https://stedolan.github.io/jq/).
#!/bin/sh
echo '"country","city","latitude","longitude","ISP","organization","IP"'
sudo iptables-save | grep sshguard | grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | xargs -I{} curl -s http://ip-api.com/json/{} | jq -r '[.country, .city, .lat, .lon, .isp, .org, .query] | @csv'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment