Last active
February 14, 2024 12:37
-
-
Save Bsebring/afcd0ab2c42d5fd603582c7ded2e9368 to your computer and use it in GitHub Desktop.
Python implementation of csf integration
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 | |
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