-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadblocker.py
66 lines (57 loc) · 2.35 KB
/
adblocker.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
#!/usr/bin/python
import os,sys, platform
import datetime
hosts = ["https://adaway.org/hosts.txt",
"https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts"]
WINDOWS_ETC = "c:\\Windows\\System32\\Drivers\\etc\\"
WINDOWS_HOSTS = "c:\\Windows\\System32\\Drivers\\etc\\hosts"
count = 1
print(r'''
_ _ _ _
__ _ __| | |__ | | ___ ___| | _____ _ __ _ __ _ _
/ _` |/ _` | '_ \| |/ _ \ / __| |/ / _ \ '__| | '_ \| | | |
| (_| | (_| | |_) | | (_) | (__| < __/ | _ | |_) | |_| |
\__,_|\__,_|_.__/|_|\___/ \___|_|\_\___|_| (_) | .__/ \__, |
|_| |___/
@gitub.com/iam-shanmukha
''')
basename = "hosts_"
suffix = datetime.datetime.now().strftime("%d%m%y_%H%M%S")
filename = "_".join([basename, suffix])
def execute():
global count
os.system(cmd)
print(f'completed {count}/{len(hosts)}')
count = count+1
if platform.system() == 'Linux':
print("Starting Script on Linux")
try:
if os.geteuid() !=0:
raise PermissionError
os.system(r"sudo cp /etc/hosts /etc/{}".format(filename))
print("Backup success \nBackup file --> /etc/{}".format(filename))
open('/etc/hosts', 'w').close()
for i in hosts:
cmd = f'sudo curl -s {i} >> /etc/hosts'
execute()
print("Successfully Blocked Ad's")
sys.exit()
except PermissionError:
print("Please run as root \nsudo python adblocker.py")
sys.exit()
elif platform.system() == 'Windows':
print("starting Script on Windows")
try:
os.system(f'copy {WINDOWS_HOSTS} {WINDOWS_ETC}{filename} /y')
print(f'Backup success \nBackup file --> {WINDOWS_ETC}{filename}')
open(f'{WINDOWS_HOSTS}','w').close()
for i in hosts:
cmd = f'curl -s {i} >> {WINDOWS_HOSTS}'
execute()
print("Successfully Blocked AD's")
sys.exit()
except PermissionError:
print("Abort! Please run as Administrator")
sys.exit()
else:
print("Sorry! Platform Not Supported")