forked from flinteger/dnss-blocklists
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquery.py
More file actions
executable file
·50 lines (40 loc) · 1.3 KB
/
query.py
File metadata and controls
executable file
·50 lines (40 loc) · 1.3 KB
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
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Query a list of domains in blocklists
#
import sys
from typing import List
import util
def main(domains: List[str]):
blocklists = [
'blocklists/ad.domains.txt',
'blocklists/malicious.domains.txt',
'blocklists/piracy.domains.txt',
'blocklists/social_networks.domains.txt',
'blocklists/dating.domains.txt',
'blocklists/game.domains.txt',
'blocklists/gambling.domains.txt',
'blocklists/porn.domains.txt'
]
for blocklist in blocklists:
blocklist_domains = util.load_domains(blocklist)
for (rank, domain) in domains:
if domain in blocklist_domains:
print(f"{rank}: {domain} in {blocklist}")
if __name__ == '__main__':
if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} domain-file")
sys.exit(1)
rank = 0
domains = list()
# load top-N rank domains, the file content is ordered by rank.
with open(sys.argv[1]) as f:
for line in f.readlines():
domain = line.strip()
if len(domain) == 0 or domain.isspace() or domain.startswith("#"):
# skip empty or comment line
continue
rank += 1
domains.append((rank, domain))
main(domains)