├── dingoes ├── __init__.py ├── hphosts.py ├── resolver.py ├── confparser.py └── report.py ├── requirements.txt ├── LICENSE ├── services.ini ├── .gitignore ├── README.md └── dingoes.py /dingoes/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | ascii-graph==1.4.3 2 | colorama==0.3.9 3 | cursor==1.1.0 4 | decorator==4.1.2 5 | dnspython==1.15.0 6 | enum34==1.1.6 7 | etaprogress==1.1.1 8 | feedparser==5.2.1 9 | halo==0.0.7 10 | log-symbols==0.0.11 11 | netaddr==0.7.19 12 | phishtank==1.0.0 13 | pyfiglet==0.7.5 14 | python-dateutil==2.6.1 15 | six==1.11.0 16 | spinners==0.0.19 17 | termcolor==1.1.0 18 | urllib3==1.22 19 | validators==0.12.0 20 | -------------------------------------------------------------------------------- /dingoes/hphosts.py: -------------------------------------------------------------------------------- 1 | import feedparser 2 | 3 | class HpHostsFeed(object): 4 | '''HpHostsFeed class''' 5 | def __init__(self, category='PSH'): 6 | self.category = category 7 | self.feed_url = 'https://hosts-file.net/rss.asp?class=' + category 8 | self.hphosts_feed = False 9 | self.main() 10 | 11 | def main(self): 12 | self.hphosts_feed = feedparser.parse(self.feed_url) 13 | 14 | @property 15 | def entries(self): 16 | entries = self.hphosts_feed.entries 17 | return entries 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 CryptoAUSTRALIA 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /services.ini: -------------------------------------------------------------------------------- 1 | [Google Public DNS] 2 | resolvers = 8.8.8.8, 8.8.4.4 3 | blockpages = none 4 | homepage = https://developers.google.com/speed/public-dns/ 5 | 6 | [OpenDNS Home] 7 | resolvers = 208.67.222.222, 208.67.220.220 8 | blockpages = 146.112.0.0/16 9 | homepage = https://www.opendns.com/home-internet-security/ 10 | 11 | [Comodo SecureDNS] 12 | resolvers = 8.26.56.26, 8.20.247.20 13 | blockpages = 52.15.96.207 14 | homepage = https://www.comodo.com/secure-dns/ 15 | 16 | [Norton ConnectSafe] 17 | resolvers = 199.85.126.10, 199.85.127.10 18 | blockpages = 156.154.0.0/16, 34.192.0.0/10 19 | homepage = https://connectsafe.norton.com/configureRouter.html 20 | 21 | [Quad9] 22 | resolvers = 9.9.9.9 23 | blockpages = NXDOMAIN 24 | homepage = https://www.quad9.net/ 25 | 26 | [Neustar Free Recursive DNS] 27 | resolvers = 156.154.70.2, 156.154.71.2 28 | blockpages = 156.154.0.0/16 29 | homepage = https://www.neustar.biz/security/dns-services/free-recursive-dns-service 30 | 31 | [SafeDNS] 32 | resolvers = 195.46.39.39, 195.46.39.40 33 | blockpages = blockpage.safedns.com 34 | homepage = https://www.safedns.com/ 35 | 36 | [Comodo Shield] 37 | resolvers = 8.26.56.10, 8.20.247.10 38 | blockpages = 54.202.133.169, 34.202.153.71, 35.166.123.71 39 | homepage = https://shield.dome.comodo.com/ 40 | 41 | [Strongarm] 42 | resolvers = 54.174.40.213, 52.3.100.184 43 | blockpages = filtered.strongarm.io 44 | homepage = https://strongarm.io/ 45 | 46 | [Yandex.DNS] 47 | resolvers = 77.88.8.88, 77.88.8.2 48 | blockpages = safe1.yandex.ru, safe2.yandex.ru, 213.180.193.0/24 49 | homepage = https://dns.yandex.com/advanced/ 50 | 51 | [Safesurfer] 52 | resolvers = 104.155.237.225, 104.197.28.121 53 | blockpages = block.safesurfer.net.nz 54 | homepage = https://www.safesurfer.co.nz/ 55 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | ._.DS_Store 3 | *.csv 4 | 5 | # Byte-compiled / optimized / DLL files 6 | __pycache__/ 7 | *.py[cod] 8 | *$py.class 9 | 10 | # C extensions 11 | *.so 12 | 13 | # Distribution / packaging 14 | .Python 15 | env/ 16 | build/ 17 | develop-eggs/ 18 | dist/ 19 | downloads/ 20 | eggs/ 21 | .eggs/ 22 | lib/ 23 | lib64/ 24 | parts/ 25 | sdist/ 26 | var/ 27 | wheels/ 28 | *.egg-info/ 29 | .installed.cfg 30 | *.egg 31 | 32 | # PyInstaller 33 | # Usually these files are written by a python script from a template 34 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 35 | *.manifest 36 | *.spec 37 | 38 | # Installer logs 39 | pip-log.txt 40 | pip-delete-this-directory.txt 41 | 42 | # Unit test / coverage reports 43 | htmlcov/ 44 | .tox/ 45 | .coverage 46 | .coverage.* 47 | .cache 48 | nosetests.xml 49 | coverage.xml 50 | *.cover 51 | .hypothesis/ 52 | 53 | # Translations 54 | *.mo 55 | *.pot 56 | 57 | # Django stuff: 58 | *.log 59 | local_settings.py 60 | 61 | # Flask stuff: 62 | instance/ 63 | .webassets-cache 64 | 65 | # Scrapy stuff: 66 | .scrapy 67 | 68 | # Sphinx documentation 69 | docs/_build/ 70 | 71 | # PyBuilder 72 | target/ 73 | 74 | # Jupyter Notebook 75 | .ipynb_checkpoints 76 | 77 | # pyenv 78 | .python-version 79 | 80 | # celery beat schedule file 81 | celerybeat-schedule 82 | 83 | # SageMath parsed files 84 | *.sage.py 85 | 86 | # dotenv 87 | .env 88 | 89 | # virtualenv 90 | .venv 91 | venv/ 92 | ENV/ 93 | 94 | # Spyder project settings 95 | .spyderproject 96 | .spyproject 97 | 98 | # Rope project settings 99 | .ropeproject 100 | 101 | # mkdocs documentation 102 | /site 103 | 104 | # mypy 105 | .mypy_cache/ 106 | -------------------------------------------------------------------------------- /dingoes/resolver.py: -------------------------------------------------------------------------------- 1 | import dns.resolver 2 | from netaddr import * 3 | 4 | class DnsResolver(object): 5 | def __init__(self, dns_resolvers = ['8.8.8.8', '8.8.4.4'], retry_servfail=False, single_resolver=False): 6 | self.dns_query_timeout = 8.0 7 | self.dns_resolvers = dns_resolvers 8 | self.my_resolver = False 9 | self.retry_servfail = retry_servfail 10 | self.single_resolver = single_resolver 11 | self.main() 12 | 13 | def main(self): 14 | self.my_resolver = dns.resolver.Resolver() 15 | self.my_resolver.timeout = self.dns_query_timeout 16 | self.my_resolver.lifetime = self.dns_query_timeout 17 | self.my_resolver.retry_servfail = self.retry_servfail 18 | if self.single_resolver: 19 | self.my_resolver.nameservers = self.dns_resolvers[:1] 20 | else: 21 | self.my_resolver.nameservers = self.dns_resolvers 22 | 23 | def get_ip_address(self, domain): 24 | """Resolve domain name into IP address 25 | 26 | Return IPSet() and manage common DNS lookup error scenarios 27 | """ 28 | result = IPSet() 29 | try: 30 | query_responses = self.my_resolver.query(domain, 'A') 31 | for query_response in query_responses: 32 | ip_address = query_response.to_text() 33 | result.add(ip_address) 34 | except dns.resolver.NXDOMAIN: 35 | result.add('255.255.255.255/32') # Represent NXDOMAIN 36 | except dns.resolver.NoAnswer: 37 | raise Exception("DNS Response Empty") 38 | except dns.exception.Timeout: 39 | raise Exception("DNS Lookup Timeout") 40 | except dns.resolver.NoNameservers: 41 | raise Exception("DNS Lookup Error") 42 | except: 43 | raise Exception("DNS Lookup Error") 44 | return result 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DiNgoeS 2 | 3 | Compare website blocking effectiveness of popular public DNS servers 4 | 5 | This tool downloads the latest feed of malicious and deceptive websites 6 | from [hpHosts](https://hosts-file.net/) and looks up whether these websites are 7 | blocked on popular third-party malware-blocking and anti-phishing DNS 8 | services. 9 | 10 | Read the full blog article and see the initial report on the [CryptoAUSTRALIA Blog](https://blog.cryptoaustralia.org.au/2017/12/23/best-threat-blocking-dns-providers/) 11 | 12 | ## DNS Services Supported 13 | 14 | * [Comodo Secure DNS](https://www.comodo.com/secure-dns/) 15 | * [Comodo Shield](https://shield.dome.comodo.com/) 16 | * [IBM Quad 9](https://www.quad9.net/) 17 | * [Norton ConnectSafe](https://connectsafe.norton.com/configureRouter.html) 18 | * [Neustar Free Recursive DNS](https://www.neustar.biz/security/dns-services/free-recursive-dns-service) 19 | * [OpenDNS Home](https://www.opendns.com/) 20 | * [SafeDNS](https://www.safedns.com/) 21 | * [Strongarm](https://strongarm.io/) 22 | * [Yandex.DNS](https://dns.yandex.com/advanced/) 23 | 24 | ## hpHosts Feeds Supported 25 | 26 | * **PSH** : Sites engaged in Phishing (default) 27 | * **EMD** : Sites engaged in malware distribution 28 | * **EXP** : Sites engaged in hosting, development or distribution of exploits 29 | 30 | ## Install 31 | * Require python3 32 | * Install requirements with `pip`: 33 | 34 | `$ pip install -r requirements.txt` 35 | 36 | ## Usage 37 | 38 | * Run DiNgoeS with the following command: 39 | 40 | `$ python dingoes.py` 41 | 42 | The CSV format report will be available in the same directory. Open in Excel 43 | or similar for further processing. 44 | 45 | ## Switches 46 | 47 | * `-o` : CSV report file name 48 | * `-c` : hpHosts feed: `PSH` (default), `EMD` or `EXP` 49 | * `-n` : Number of websites from the hpHosts feed to test (default: 500) 50 | * `-s` : Shell type - if spinner exceptions occur, set to 1 (default: 0) 51 | 52 | ## Support 53 | 54 | Contact us on Twitter at [@CryptoAUSTRALIA](https://twitter.com/CryptoAustralia) 55 | -------------------------------------------------------------------------------- /dingoes.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # DiNgoeS: Compare anti-malware and phishing filtering DNS services 4 | # Author: https://twitter.com/gszathmari 5 | # 6 | 7 | import os 8 | import time 9 | import argparse 10 | import signal 11 | from pyfiglet import Figlet 12 | from halo import Halo 13 | from sys import exit 14 | from dingoes.hphosts import HpHostsFeed 15 | from dingoes.report import Report 16 | from dingoes.confparser import ConfParse 17 | 18 | import logging 19 | 20 | def print_banner(): 21 | """Print welcome banner 22 | 23 | """ 24 | figlet = Figlet(font='slant') 25 | banner = figlet.renderText('DiNgoeS') 26 | print(banner) 27 | print("[+] 2017 CryptoAUSTRALIA - https://cryptoaustralia.org.au\n") 28 | 29 | def get_args(): 30 | """Get command line arguments 31 | 32 | """ 33 | epoch_time = int(time.time()) 34 | report_filename = "report_{}_{}.csv".format(time.strftime("%Y-%m-%d_%H%M"), epoch_time) 35 | parser = argparse.ArgumentParser( 36 | description='Compare DNS server responses.',formatter_class=argparse.MetavarTypeHelpFormatter) 37 | parser.add_argument('-o', type=str, default=report_filename, help='Report file name') 38 | parser.add_argument('-c', type=str, help='hpHosts feed (Default: PSH)', choices=['PSH', 'EMD', 'EXP'], default='PSH') 39 | parser.add_argument('-n', type=int, help='Number of hishing sites to test (Default: 500)', default=500) 40 | parser.add_argument('-s', type=int, help='Shell type: set to 1 if spinner errors occur (default: 0)', default=0) 41 | args = parser.parse_args() 42 | return args 43 | 44 | def main(): 45 | print_banner() 46 | args = get_args() 47 | if( args.s == 0 ): 48 | spinner = Halo(spinner='dots') 49 | try: 50 | if (args.s == 0): 51 | spinner.start(text='Parsing configuration file') 52 | config = ConfParse() 53 | if (args.s == 0): 54 | spinner.succeed() 55 | except Exception as e: 56 | if(args.s == 0): 57 | spinner.fail() 58 | print("\n\nError parsing configuration file: {}\n".format(e)) 59 | exit(1) 60 | try: 61 | if(args.s == 0): 62 | spinner.start(text="Retrieving hpHosts feed: {}".format(args.c)) 63 | hphosts_feed = HpHostsFeed(args.c) 64 | if(args.s == 0): 65 | spinner.succeed() 66 | except Exception as e: 67 | if(args.s == 0): 68 | spinner.fail() 69 | print("\n\nError retrieving hpHosts feed: {}\n".format(e)) 70 | exit(1) 71 | # Create object and load in the retrieved values from above 72 | report_filename = "hpHosts-{}-{}".format(args.c, args.o) 73 | report = Report(hphosts_feed, report_filename, config) 74 | # Process results 75 | print("\nProcessing {} entries, this may take a while:\n".format(args.n)) 76 | report.write_results(args.n) 77 | print("\nGreat success.\n") 78 | # Plot stats histogram 79 | if(args.s==0): 80 | report.print_stats_diagram(args.n) 81 | print("\nDetailed report is available in {}\n".format(report_filename)) 82 | 83 | def signal_handler(signal, frame): 84 | print('\n\nYou pressed Ctrl+C!\n') 85 | os._exit(1) 86 | 87 | if __name__ == '__main__': 88 | signal.signal(signal.SIGINT, signal_handler) 89 | main() 90 | -------------------------------------------------------------------------------- /dingoes/confparser.py: -------------------------------------------------------------------------------- 1 | import re 2 | import configparser 3 | from validators.ip_address import ipv4 4 | from validators.domain import domain 5 | from netaddr import * 6 | from dingoes.resolver import DnsResolver 7 | 8 | class ConfParse(object): 9 | '''ConfParse class''' 10 | def __init__(self, file_name="services.ini"): 11 | self.file_name = file_name 12 | self.config_parser = False 13 | self.config = {} 14 | self.dns_resolver = DnsResolver() 15 | self.main() 16 | 17 | def main(self): 18 | self.config_parser = configparser.ConfigParser() 19 | self.config_parser.read_file(open(self.file_name)) 20 | for entry in self.config_parser.sections(): 21 | resolvers = self.config_parser[entry]['resolvers'] 22 | blockpages = self.config_parser[entry]['blockpages'] 23 | self.config[entry] = { 24 | 'resolvers': self.parse_resolvers(resolvers), 25 | 'blockpages': self.parse_blockpages(blockpages) 26 | } 27 | 28 | def parse_resolvers(self, resolvers): 29 | '''Parses IP addresses from the configuration file''' 30 | # TODO: Change this to IPSet() 31 | result = [] 32 | # Strip whitespaces 33 | resolvers_list = [x.strip() for x in resolvers.split(',')] 34 | # Validate IP addresses 35 | for ip_address in resolvers_list: 36 | # If the IP is valid, add to the results 37 | if ipv4(ip_address): 38 | result.append(ip_address) 39 | else: 40 | raise Exception("Invalid IP address in configuration file: {}".format(ip_address)) 41 | return result 42 | 43 | def parse_blockpages(self, blockpages): 44 | ''' 45 | Parses 'blockpages =' entry from the configuration file 46 | 47 | Get the IP address or domain name from the config file of the blocked pages 48 | and add them into an IPSet. 49 | ''' 50 | result = IPSet() 51 | # Split entries from the config file and strip whitespaces 52 | blockpages_list = [x.strip() for x in blockpages.split(',')] 53 | # Process the IP addresses and domains 54 | for blockpage in blockpages_list: 55 | # If the DNS server blocks the query with NXDOMAIN 56 | if blockpage == 'NXDOMAIN': 57 | # Represent NXDOMAIN with 255.255.255.255/32 58 | result.add('255.255.255.255/32') 59 | # If the block page is hosted on a simple IP address 60 | elif ipv4(blockpage): 61 | result.add(blockpage) 62 | # If the block page is hosted somewhere on a subnet 63 | elif re.match('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(?:/\d{1,2}|)', blockpage): 64 | result.add(blockpage) 65 | # If the block page is hosted under a CNAME record 66 | elif domain(blockpage): 67 | try: 68 | result = self.dns_resolver.get_ip_address(blockpage) 69 | except Exception as e: 70 | print("\nDNS resolution error while retrieving list of block pages: {}\n".format(e)) 71 | exit(1) 72 | # If the 'blockpage = ' has a 'none' value (e.g. Google DNS doesn't have a block page) 73 | elif blockpage == 'none': 74 | pass 75 | # Throw exception if an invalid entry is found 76 | else: 77 | raise Exception("Invalid entry found: {}".format(blockpage)) 78 | return result 79 | 80 | @property 81 | def confvalues(self): 82 | return self.config 83 | -------------------------------------------------------------------------------- /dingoes/report.py: -------------------------------------------------------------------------------- 1 | import csv 2 | import re 3 | from etaprogress.progress import ProgressBar 4 | from dateutil.parser import parse 5 | from netaddr import * 6 | from dingoes.resolver import DnsResolver 7 | from ascii_graph import Pyasciigraph 8 | from ascii_graph.colors import * 9 | from ascii_graph.colordata import vcolor 10 | 11 | class Report(object): 12 | '''Report class''' 13 | def __init__(self, hphosts_feed, output_file, config): 14 | self.hphosts_feed = hphosts_feed 15 | self.output_file = output_file 16 | self.output_file_handler = False 17 | self.config = config 18 | self.resolver = DnsResolver(retry_servfail=True) 19 | self.csv_writer = False 20 | self.resolvers = config.confvalues 21 | self.resolver_names = config.confvalues.keys() 22 | self.statistics = {} 23 | # Initialise stats dict 24 | for item in self.resolver_names: 25 | self.statistics[item] = 0 26 | 27 | def is_blocked(self, ip_addresses, blockpages, phishing_domain): 28 | '''Verifies whether the IP address is on the blocked page list''' 29 | # TODO: blockpages should be generated from self.config 30 | intersection = ip_addresses & blockpages 31 | # If response was NXDOMAIN, we need to verify if a non-filtering server respond with NXDOMAIN too 32 | # e.g. the domain is taken down 33 | if IPAddress('255.255.255.255') in ip_addresses: 34 | try: 35 | # Get the IP address from Google DNS 36 | google_dns_response = self.resolver.get_ip_address(phishing_domain) 37 | nx_intersection = ip_addresses & google_dns_response 38 | # If Google DNS and the DNS server responds with different results, the 39 | # blocking was unsuccessful 40 | if len(nx_intersection) == 0: 41 | response = 'NXDOMAIN' 42 | return response 43 | # If Google DNS and the DNS server under inspection responds with the same IP addresses 44 | # the block is unsuccessful 45 | else: 46 | return False 47 | # If response is NXDOMAIN from Google DNS, or any other error, return False 48 | # which means we could not determine whether the site was blocked or not 49 | except: 50 | return False 51 | elif len(intersection) > 0: 52 | # If the IP address is in the list of IP addresses of block pages 53 | # the website is blocked successfully 54 | return intersection 55 | # Return 'non-blocked' in case of any other errors 56 | else: 57 | return False 58 | 59 | def generate_result(self, ip_addresses, blockpages, resolver_name, phishing_domain): 60 | """ 61 | Generates cell content in the CSV file 62 | """ 63 | result = False 64 | # Return 'SITE_BLOCKED_OK' if the phishing site's domain name resolves to 65 | # one of the block pages of the DNS services. 66 | if self.is_blocked(ip_addresses, blockpages, phishing_domain): 67 | result = 'SITE_BLOCKED_OK' 68 | self.add_to_stats(resolver_name) 69 | # If the website is not blocked, return with the website's IP address 70 | else: 71 | results = [] 72 | for ip_address in ip_addresses: 73 | results.append(str(ip_address)) 74 | result = "\n".join(results) 75 | return result 76 | 77 | def open_csv_file(self): 78 | '''Open CSV file and add header''' 79 | try: 80 | self.output_file_handler = open(self.output_file, 'w') 81 | except Exception as e: 82 | print("\n\nError opening output file {}: {}\n".format(args.o, e)) 83 | exit(1) 84 | csv_header_fieldnames = [ 85 | 'Added to hpHosts', 86 | 'Phishing Site Domain', 87 | 'Phishing Site IP Address' 88 | ] 89 | csv_header_fieldnames.extend(sorted(self.resolver_names)) 90 | csv_writer = csv.DictWriter(self.output_file_handler, delimiter=',', fieldnames=csv_header_fieldnames) 91 | csv_writer.writeheader() 92 | return csv_writer 93 | 94 | def write_results(self, entries_to_process): 95 | '''Write results into CSV file''' 96 | counter = 1 97 | # Create progress bar 98 | bar = ProgressBar(entries_to_process, max_width=72) 99 | # Write CSV header 100 | csv_writer = self.open_csv_file() 101 | # Iter through each feed entry from the hpHosts feed 102 | for feed_entry in self.hphosts_feed.entries: 103 | # Stop processing if the number of entries are higher than in '-n' 104 | if counter > entries_to_process: 105 | break 106 | result = {} 107 | # Update progress bar 108 | bar.numerator = counter 109 | print(bar, end='\r') 110 | # Write phishing site details into CSV 111 | result['Phishing Site Domain'] = feed_entry.title 112 | result['Added to hpHosts'] = parse(feed_entry.published) 113 | result['Phishing Site IP Address'] = re.findall(r'[0-9]+(?:\.[0-9]+){3}', feed_entry.summary)[0] 114 | # Iterate through the third-party DNS services 115 | for resolver_name in self.resolver_names: 116 | try: 117 | dns_resolvers = self.resolvers[resolver_name]['resolvers'] 118 | phishing_domain = result['Phishing Site Domain'] 119 | resolver = DnsResolver(dns_resolvers, single_resolver=True) 120 | # Retrieve the IP addresses that the third-party DNS service resolves 121 | ip_addresses = resolver.get_ip_address(phishing_domain) 122 | except Exception as e: 123 | # Write DNS lookup error message in the CSV file 124 | result[resolver_name] = e 125 | else: 126 | blockpages = self.resolvers[resolver_name]['blockpages'] 127 | result[resolver_name] = self.generate_result(ip_addresses, blockpages, resolver_name, phishing_domain) 128 | # Write results into file 129 | csv_writer.writerow(result) 130 | # Flush file after writing each line 131 | self.output_file_handler.flush() 132 | counter += 1 133 | # Close output file 134 | self.output_file_handler.close() 135 | return counter 136 | 137 | def add_to_stats(self, resolver_name): 138 | self.statistics[resolver_name] += 1 139 | 140 | def print_stats_diagram(self, total_entries): 141 | data = [] 142 | graph = Pyasciigraph(separator_length=4) 143 | for resolver_name in sorted(self.resolver_names): 144 | item = (resolver_name, self.statistics[resolver_name]) 145 | data.append(item) 146 | item = ('TOTAL', total_entries) 147 | data.append(item) 148 | for line in graph.graph('Blocking Statistics:', data): 149 | print(line) 150 | --------------------------------------------------------------------------------