-
Notifications
You must be signed in to change notification settings - Fork 68
/
smb-share-scanner.py
executable file
·55 lines (42 loc) · 1.22 KB
/
smb-share-scanner.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
#!/usr/bin/python3
import sys
import os
from random import randint
def get_ips(start_ip, stop_ip):
ips = []
tmp = []
for i in start_ip.split('.'):
tmp.append("%02X" % int(i))
start_dec = int(''.join(tmp), 16)
tmp = []
for i in stop_ip.split('.'):
tmp.append("%02X" % int(i))
stop_dec = int(''.join(tmp), 16)
while(start_dec < stop_dec + 1):
bytes = []
bytes.append(str(int(start_dec / 16777216)))
rem = start_dec % 16777216
bytes.append(str(int(rem / 65536)))
rem = rem % 65536
bytes.append(str(int(rem / 256)))
rem = rem % 256
bytes.append(str(rem))
ips.append(".".join(bytes))
start_dec += 1
return ips
def smb_share_scan(ip):
os.system("smbclient -q -N -L " + ip)
if len(sys.argv) < 2:
print(sys.argv[0] + ": <start_ip-stop_ip>")
sys.exit(1)
else:
if sys.argv[1].find('-') > 0:
start_ip, stop_ip = sys.argv[1].split("-")
ips = get_ips(start_ip, stop_ip)
while len(ips) > 0:
i = randint(0, len(ips) - 1)
lookup_ip = str(ips[i])
del ips[i]
smb_share_scan(lookup_ip)
else:
smb_share_scan(sys.argv[1])