Python implementation of csf integration
#!/usr/bin/env python | |
import requests | |
import json | |
import sys | |
# Defining the api-endpoint | |
url = 'https://api.abuseipdb.com/api/v2/report' | |
ports = sys.argv[2] | |
inOut = sys.argv[4] | |
message = sys.argv[6] | |
logs = sys.argv[7] | |
trigger = sys.argv[8] | |
comment = message + "; Ports: " + ports + "; Direction: " + inOut + "; Trigger: " + trigger + "; Logs: " + logs | |
headers = { | |
'Accept': 'application/json', | |
'Key': '$YOUR_API_KEY' | |
} | |
# String holding parameters to pass in json format | |
querystring = { | |
'ip':sys.argv[1], | |
'categories':'14', | |
'comment':comment | |
} | |
response = requests.request(method='POST', url=url, headers=headers, params=querystring) | |
decodedResponse = json.loads(response.text) | |
if response.status_code == 200: | |
print(json.dumps(decodedResponse['data'], sort_keys=True, indent=4)) | |
elif response.status_code == 429: | |
print (json.dumps(decodedResponse['errors'][0], sort_keys=True, indent=4)) | |
elif response.status_code == 422: | |
print (json.dumps(decodedResponse['errors'][0], sort_keys=True, indent=4)) | |
elif response.status_code == 302: | |
print('Unsecure protocol requested. Redirected to HTTPS.') | |
elif response.status_code == 401: | |
print (json.dumps(decodedResponse['errors'][0], sort_keys=True, indent=4)) | |
else: | |
print('Unexpected server response. Status Code:' + response.status_code) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment