This repository has been archived by the owner on Jul 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
BLU.py
91 lines (82 loc) · 5.96 KB
/
BLU.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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Energized Blu
import urllib.request
import datetime
import os
import time
File = 'energized/blu'
List = []
# Thanks to all maintainers of hosts lists.
Sources = [
'https://github.com/raw/AdroitAdorKhan/Energized/master/EnergizedHosts/EnergizedHosts',
'https://github.com/raw/StevenBlack/hosts/master/alternates/fakenews-gambling/hosts',
'http://someonewhocares.org/hosts/zero/',
'https://hblock.molinero.xyz/hosts',
'https://github.com/raw/EnergizedProtection/EnergizedTools/master/Mirror/1HostsCF/1hosts.cf.txt',
'https://github.com/raw/EnergizedProtection/EnergizedTools/master/Mirror/MoaAB/MoaAB.active.txt',
'https://github.com/raw/hoshsadiq/adblock-nocoin-list/master/hosts.txt',
'https://github.com/raw/Yhonay/antipopads/master/hosts',
'https://github.com/raw/notracking/hosts-blocklists/master/hostnames.txt',
'https://github.com/raw/FadeMind/hosts.extras/master/add.2o7Net/hosts',
'https://github.com/raw/FadeMind/hosts.extras/master/add.Dead/hosts',
'https://github.com/raw/FadeMind/hosts.extras/master/add.Risk/hosts',
'https://github.com/raw/FadeMind/hosts.extras/master/add.Spam/hosts',
'https://github.com/raw/EnergizedProtection/EnergizedTools/master/Converter/Hosts/ZeusTracker.txt',
'https://github.com/raw/StevenBlack/hosts/master/data/StevenBlack/hosts',
'https://github.com/raw/jawz101/MobileAdTrackers/master/hosts',
'https://zerodot1.gitlab.io/CoinBlockerLists/hosts_browser',
'https://zerodot1.gitlab.io/CoinBlockerLists/hosts',
'https://github.com/raw/EnergizedProtection/EnergizedTools/master/Converter/Hosts/Spam404.txt',
'https://github.com/raw/CHEF-KOCH/NSABlocklist/master/HOSTS',
'https://github.com/raw/azet12/KADhosts/master/KADhosts.txt',
'https://github.com/raw/EnergizedProtection/EnergizedTools/master/Converter/Hosts/AdguardMobileSpyware.txt',
'https://github.com/raw/EnergizedProtection/EnergizedTools/master/Converter/Hosts/AdguardTracking.txt',
'https://github.com/raw/EnergizedProtection/EnergizedTools/master/Converter/Hosts/EasylistAdserver.txt',
'https://github.com/raw/EnergizedProtection/EnergizedTools/master/Converter/Hosts/EasyPrivacySpecific.txt',
'https://github.com/raw/EnergizedProtection/EnergizedTools/master/Converter/Hosts/EasyPrivacyTracking.txt',
'https://github.com/raw/EnergizedProtection/EnergizedTools/master/Converter/Hosts/DisconnectMEAds.txt',
'https://github.com/raw/EnergizedProtection/EnergizedTools/master/Converter/Hosts/DisconnectMEMalvertising.txt',
'https://github.com/raw/EnergizedProtection/EnergizedTools/master/Converter/Hosts/DisconnectMEMalware.txt',
'https://github.com/raw/EnergizedProtection/EnergizedTools/master/Converter/Hosts/Wally3K_Blacklist.txt'
]
for Link in Sources:
try:
print('[+] Retrieving list from: {}'.format(Link))
r = urllib.request.urlopen(Link)
Host = r.readlines()
Host = [x.decode('UTF-8') for x in Host]
Host = [x.strip() for x in Host]
Host = [z for z in Host if z != '' and z[0] != '#']
Host = [h.split()[1] for h in Host if h.split()[0] in ['0.0.0.0', '127.0.0.1']]
Host = [x for x in Host if x not in ['localhost', 'localhost.localdomain', 'locals']]
print('[+] Found {} domains to block.'.format(str(len(Host))))
r.close()
List += Host
except:
print('[-] ERROR: I can\'t retrieve the list from: {}'.format(Link))
print('[+] Removing duplicates and sorting...')
List = sorted(list(set(List)))
print('[+] Applying whitelist...')
r = urllib.request.urlopen('https://github.com/raw/AdroitAdorKhan/Energized/master/EnergizedHosts/EnergizedWhites')
Whitelist = r.readlines()
Whitelist = [x.decode('utf-8') for x in Whitelist]
Whitelist = [x.strip() for x in Whitelist]
Whitelist = [z for z in Whitelist if z != '' and z[0] != '#']
r.close()
for i in range(0, len(Whitelist)):
try:
List.remove(Whitelist[i])
except:
pass
print('[+] Total domains count {}.'.format(str(len(List))))
if not os.path.exists(os.path.dirname(File)):
os.makedirs(os.path.dirname(File))
with open(File, 'w') as f:
print('[+] Writing to file...')
f.write('''# Energized - ad.porn.malware blocking.\n# A merged collection of hosts from reputable sources.\n# https://ador.chorompotro.com\n\n# Energized Blu - Lightweight Energized Protection.\n# Version: ''' + time.strftime("%y.%m.%j", time.gmtime()) + '''\n# Project Git: https://github.com/EnergizedProtection/EnergizedBlu\n# RAW Source: https://github.com/raw/EnergizedProtection/EnergizedBlu/master/energized/blu\n# Last updated: {}'''.format(datetime.datetime.now().strftime('%a, %d %b %y %X')))
f.write('''\n# Total Domains: {}\n\n'''.format(str(len(List))))
f.write('''\n# -================-Maintainer-================-\n# Nayem Ador - https://adroitadorkhan.github.io\n# -============================================-\n\n''')
f.write('''\n127.0.0.1 localhost\n127.0.0.1 localhost.localdomain\n127.0.0.1 local\n255.255.255.255 broadcasthost\n::1 localhost\n::1 ip6-localhost\n::1 ip6-loopback\nfe80::1%lo0 localhost\nff00::0 ip6-localnet\nff00::0 ip6-mcastprefix\nff02::1 ip6-allnodes\nff02::2 ip6-allrouters\nff02::3 ip6-allhosts\n0.0.0.0 0.0.0.0\n\n\n# -====================-Features-====================-\n# # Lightweight Energized Protection Ever! #\n#\n# - Based on Hosts file, all the bad stuff blocked with 0.0.0.0 \n# - Compatible with all devices, regardless of OS. \n# - Strictly blocks all advertisements, malwares, spams, statistics, trackers on both web browsing and applications. \n# - YouTube, Spotify, UC and Shareit Ads Blocking. \n# - Reduces page loading time. \n# - Reduces data consumptions. Saves data expenses. \n# - Increases privacy. \n# - No extra abracadabra!\n#\n# -==================================================-\n\n\n''')
f.write('\n'.join('0.0.0.0 ' + url for url in List))
print('[+] Done!')