Last active
January 4, 2016 05:29
-
-
Save cedricbonhomme/8575427 to your computer and use it in GitHub Desktop.
Get informations about IP banned by fail2ban.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import json | |
import requests | |
# https://github.com/CIRCL/bgpranking-redis-api/tree/master/example/api_web/client | |
from bgpranking_web import api | |
with open("/var/log/fail2ban.log", "r") as f: | |
log = f.read() | |
ip_candidates = re.findall(r"Ban (\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)", log) | |
#ip_candidates = ["221.8.18.15"] | |
for ip in ip_candidates: | |
result = requests.get("http://ipinfo.io/" + ip + "/json/") | |
json_result = json.loads(result.text) | |
asn_number = json_result["org"].split(" ")[0].replace("AS", "") | |
asn = api.asn_description(asn_number) | |
print("IP: " + ip) | |
print("Loc: %s / %s / %s" % (json_result["city"], json_result["region"], json_result["loc"])) | |
print("ASN: " + asn_number) | |
if None != asn: | |
print(asn["asn_description"]) | |
print(asn["sources"]) | |
print("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment