File: reputation.py

package info (click to toggle)
python-pyfunceble 4.2.29.dev-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,108 kB
  • sloc: python: 27,413; sh: 142; makefile: 27
file content (40 lines) | stat: -rw-r--r-- 1,204 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
This is an example which checks that the test with the reputation data is correct.
"""

import colorama

from PyFunceble import DomainAndIPReputationChecker
from PyFunceble.dataset.ipv4_reputation import IPV4ReputationDataset

reputation_checker = DomainAndIPReputationChecker()
reputation_dataset = IPV4ReputationDataset().get_content()

LIMIT = 10
MALICIOUS_SUBJECTS = [
    next(reputation_dataset).split("#", 1)[0] for _ in range(LIMIT + 1)
]

SANE_SUBJECTS = ["twitter.com", "google.com", "github.com"]

if __name__ == "__main__":
    colorama.init(autoreset=True)

    for subject in MALICIOUS_SUBJECTS:
        reputation_checker.subject = subject
        status = reputation_checker.get_status()

        if not status.is_malicious():
            raise RuntimeError(f"Something is wrong with {subject}.")
        print(f"{subject} is {status.status}")

    for subject in SANE_SUBJECTS:
        reputation_checker.subject = subject
        status = reputation_checker.get_status()

        if not status.is_sane():

            raise RuntimeError(
                f"Something is wrong with {subject}. Dataset:\n{status.to_json()}"
            )
        print(f"{subject} is {status.status}")