-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblock.py
32 lines (22 loc) · 886 Bytes
/
block.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
import os
import sys
def slice_list(s, step):
if s is not None:
return [s[x:x+step] for x in range(0, len(s), step)]
else:
return []
if len(sys.argv) != 2:
print("Usage: py -3 block.py <IPs file>")
exit(1)
with open(sys.argv[1]) as ip_file:
ip_list = [ip.split('\t')[0] for ip in ip_file.read().splitlines()]
for i, ip_block in enumerate(slice_list(ip_list, 500)):
# Creating blocking rule
os.system(f'netsh advfirewall firewall add rule name="ApexBlock{i}" dir=out action=block remoteip=111.111.111.111')
# Creating a netsh script
netsh_script = f"pushd advfirewall firewall set rule name=\"ApexBlock{i}\" new remoteip={','.join(ip_block)}"
# Executing the netsh script
with open('netsh.nsh', 'w') as netsh_file:
netsh_file.write(netsh_script)
os.system('netsh -f netsh.nsh')
os.remove('netsh.nsh')