-
Notifications
You must be signed in to change notification settings - Fork 1
/
RBLMonitor_db.py
executable file
·103 lines (76 loc) · 2.72 KB
/
RBLMonitor_db.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/python3
#####################################
# #
# Real-Time Black List Monitor #
# Database Setup & objects #
# #
# By: Wayne Simmerson #
# https://github.com/wsimmerson #
# #
#####################################
from sqlalchemy import create_engine, ForeignKey
from sqlalchemy import Column, DateTime, Integer, String
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from datetime import datetime
engine = create_engine('sqlite:///RBLMonitor.db', echo=True)
Base = declarative_base()
#############################
class Blacklist(Base):
"""
"""
__tablename__ = "blacklists"
id = Column(Integer, primary_key=True)
name = Column(String)
url = Column(String)
def __init__(self, name, url):
self.name = name
self.url = url
############################
class Server(Base):
"""
"""
__tablename__ = "servers"
id = Column(Integer, primary_key=True)
name = Column(String)
ip_address = Column(String)
def __init__(self, name, ip_address):
self.name = name
self.ip_address = ip_address
############################
class Listing(Base):
"""
"""
__tablename__ = "listings"
id = Column(Integer, primary_key=True)
blacklist_id = Column(Integer, ForeignKey('blacklists.id'))
server_id = Column(Integer, ForeignKey('servers.id'))
logged = Column(DateTime, default=datetime.utcnow)
def __init__(self, blacklist_id, server_id):
self.blacklist_id = blacklist_id
self.server_id = server_id
###########################
if __name__ == '__main__':
Base.metadata.create_all(engine)
engine = create_engine('sqlite:///RBLMonitor.db', echo=False)
Session = sessionmaker(bind=engine)
session = Session()
RBLS = {'Spamhaus-Zen': 'zen.spamhaus.org',
'Spamcop': 'bl.spamcop.net',
'Sorbs': 'dnsbl.sorbs.net',
'Barracuda': 'b.barracudacentral.org',
'Mailspike-Blacklist': 'bl.mailspike.net',
'Mailspike-Reputation': 'rep.mailspike.net',
'McAfee': 'cidr.bl.mcafee.com',
'Microsoft Forefront': 'dnsbl.forefront.microsoft.com',
'nsZones': 'bl.nszones.com',
'ORBIT': 'rbl.orbit.com',
'Pedantic-Netblock': 'netblock.pedantic.org',
'Pedantic-Spam': 'spam.pedantic.org',
'Lashback': 'ubl.unsubscore.com',
'Backscatterer': 'ips.backscatterer.org'
}
# populate rbls from above
for name, rbl in RBLS.items():
session.add(Blacklist(name, rbl))
session.commit()