-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan_lan.py
61 lines (50 loc) · 1.74 KB
/
scan_lan.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
import os
def extract_info():
f = os.popen('ifconfig eth0 | grep "inet\ addr" | cut -d: -f2 | cut -d" " -f1')
your_ip=f.read()
f = os.popen('ifconfig eth0 | grep "inet\ addr" | cut -d: -f4')
your_mask=f.read()[:-1]
return your_ip, your_mask
def check_1(your_ip, your_mask):
lips = []
a = your_mask.split(".")
print a
if a[1] == 0:
lips = chech_barra8(your_ip)
elif a[2] == 0:
lips = check_barra16(your_ip)
elif a[3] == 0:
lips = check_barra24(your_ip)
return lips
def check_barra8(your_ip):
lista_ip = []
first_num = your_ip.split(".")[0]
for i in range(1, 255):
for j in range(1, 255):
for k in range (1, 255):
ipp = first_num+str(i)+str(j)+str(k)
lista_ip.append(ipp)
return lista_ip
def check_barra16(your_ip):
lista_ip = []
first_num = your_ip.split(".")[0]
second_num = your_ip.split(".")[1]
for i in range(1, 255):
for j in range(1, 255):
ipp = first_num+second_num+str(j)+str(k)
lista_ip.append(ipp)
return lista_ip
def check_barra24(your_ip):
lista_ip = []
first_num = your_ip.split(".")[0]
second_num = your_ip.split(".")[1]
third_num = your_ip.split(".")[2]
for k in range(1, 255):
ipp = first_num+second_num+sthird_num+str(k)
lista_ip.append(ipp)
return lista_ip
if __name__ == "__main__":
ip, mask = extract_info()
l_ips = []
l_ips = check_1(ip, mask)
print l_ips