Skip to content

AbuseIpDB - Wrapper around the AbuseIPDb service API

License

Notifications You must be signed in to change notification settings

Eorhim/AbuseIpDb

 
 

Repository files navigation

AbuseIpDb - Wrapper around the Abuse IP DB service API

The package supports APIv2. No other API is currently available. Uploading a CSV report of abusive IP addresses is not yet implemented.

Installing

pip install abuseipdb

Usage as a python module

To choose between the API versions, you pass the version as the second parameter. Use the string APIv2 to select the API version.

from abuseipdb import AbuseIpDb
abuse_v2 = AbuseIpDb(api_key='APIv2key', api_version='APIv2')  # Using API v2
abuse = AbuseIpDb(api_key='APIv2key')                          # Also using API v2

If you have a subscription plan with Abuse IP DB, you can indicate this with an additional parameter. This has only an effect for the APIv2.

from abuseipdb import AbuseIpDb
abuse = AbuseIpDb(api_key='APIv2key', subscriber=True)

Checking a single IP address

abuse.check(ip_address="192.0.2.123")
abuse.check(ip_address="192.0.2.123", max_age_in_days=90)

Checking for a CIDR network block

abuse.check_block(cidr_network="192.0.2.0/24")
abuse.check_block(cidr_network="192.0.2.0/24", max_age_in_days=90)

Report an abusive IP address

All the following calls result in the same call to AbuseIpDb. If yyou pass in an unkonwn category, it will raise a ValueError.

abuse.report(ip_address="192.0.2.123", categories="15,22")
abuse.report(ip_address="192.0.2.123", categories="15, 22")
abuse.report(ip_address="192.0.2.123", categories="HACKING, SSH")
abuse.report(ip_address="192.0.2.123", categories=(15, 22))
abuse.report(ip_address="192.0.2.123", categories=("15", "22"))
abuse.report(ip_address="192.0.2.123", categories=[15, "SSH"])

This adds a comment to the report.

abuse.report(ip_address="192.0.2.123", categories=("13", "22"),
             comment="Some comment about the abusive IP address")

### Report a list of abusive IP addresses

Please refer to [IP Bulk Reporter](https://www.abuseipdb.com/bulk-report)
for the exact specification of the CSV file.

```python
abuse.bulk_report(file_name="report.csv")

Retrieve a list of abusive IP addresses

abuse.blacklist()
abuse.blacklist(limit=10)             # Only get 10 entries
abuse.blacklist(confidence_level=90)  # Only available for subscribers

Usage on the command line

You can invoke the module on the command line. It supports all the commands listed above. For the explicit syntax and the required configuration call it with the --help parameter.

abuseipdb --help

Project links


About

AbuseIpDB - Wrapper around the AbuseIPDb service API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%