Navigation
Artikel
Stuff
RSS Feeds
|
Sourcecodes - DNSBL testenSprachenübersicht/Python/DNS Keywords: check dnsbl blacklist mail server ip tool Erklärung Top
Abhängigkeiten Top
Code Top
Code: #!/usr/bin/env python import DNS import os, sys from smtplib import SMTP from datetime import datetime # list of mailserver to check for mail_servers = [ '62.2.100.201', '62.2.100.202', ] # list of blacklists to check blacklists = [ 'sbl-xbl.spamhaus.org', 'list.dsbl.org', 'bl.spamcop.net', 'dnsbl1.dnsbl.borderware.com', 'dnsbl2.dnsbl.borderware.com', 'dnsbl.sorbs.net', ] # list of dns resolving server servers = [ '62.2.100.201', '194.183.128.35', ] # mail relay for email notification mail_relay = "localhost" mail_from = "admin@host.domain.tld" mail_recipients = [ "admin1@domain.tld", "admin2@domain.tld", ] def blquery(ip, bl): tmp = ip.split('.') tmp.reverse() rev_ip = '.'.join(tmp) querydomain = ip + '.' + bl req = dns.req(querydomain) if req.answers: msg = 'Server %s in blacklist %s\n' % (ip, bl) req = dns.req(querydomain, qtype='TXT') if req.answers: msg += 'Info: %s\n\n' % req.answers[0]['data'] return msg return '' def main(): global mail_from msg = '' for ip in mail_servers: for bl in blacklists: msg += blquery(ip, bl) if not msg: sys.exit(0) if not mail_from: mail_from = "root@"+os.uname()[1] header = 'From: %s\n' % mail_from header += 'To: %s\n' % ','.join(mail_recipients) header += 'Date: %s\n' % datetime.now().ctime() header += 'Subject: Mail Server in Blacklist\n' smtp = SMTP(mail_relay) smtp.sendmail(mail_from, mail_recipients, header + '\n\n' + msg) smtp.quit() if __name__ == '__main__': dns = DNS.Request(server = servers) main() Gibt es noch irgendwelche Fragen, oder wollen Sie über den Artikel diskutieren? Sprachenübersicht/Python/DNS/DNSBL testen |