Skip to content

Instantly share code, notes, and snippets.

@qunwang6
Forked from rlei/sshguard_banned_ips.sh
Created March 7, 2020 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qunwang6/3cd4b7c67f5c4ce0515f9d6f83019755 to your computer and use it in GitHub Desktop.
Save qunwang6/3cd4b7c67f5c4ce0515f9d6f83019755 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