-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathip_scanner.py
81 lines (56 loc) · 1.94 KB
/
ip_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import platform
import subprocess
from subprocess import PIPE
import socket
import threading
######## sistem windows mu linux mi ################
print(platform.system().lower())
###################################################
#### kodun calistigi bilgisayarin ipsini almak ##############
aa=[(s.connect(("8.8.8.8", 53)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]]
aa1=aa[0][1]
###############################################################
iptaban=aa1.split(".")
###############################################################
myThreadList = []
iplist=[]
host=""
###############################################################
def b1(a1,a2):
iptaban=aa1.split(".")
iptaban1=iptaban[0]+"."+iptaban[1]+"."+iptaban[2]+"."+a1
iptaban2=iptaban[0]+"."+iptaban[1]+"."+iptaban[2]+"."+a2
tarailk=iptaban1.split(".")
tarailk1=int(tarailk[3])
tarason=iptaban2.split(".")
tarason1=int(tarason[3])
for iii in range(tarailk1,tarason1):
host=iptaban[0]+"."+iptaban[1]+"."+iptaban[2]+"."+str(iii)
#comand1=['ping ','-n','1','-w','1',host]
#print(host)
comand=['ping ',"-f",'-w','1','-n','1',host]
if subprocess.call(comand,shell = False,stdout=PIPE) == 0 :
#print("bulunan ip = "+host)
iplist.append(host)
#https://stackoverflow.com/questions/11968689/python-multithreading-wait-till-all-threads-finished
def ip_scan(ip_begin,ip_end):
if platform.system().lower()!="windows":
return "op system must be windows"
if ip_end > 256:
return "ip_end must be maximum 256"
myThreadList=[]
for aaa in range(ip_begin,ip_end,5):
myThread=threading.Thread(target=b1,args=(str(aaa),str(aaa+5)))
myThreadList.append(myThread)
for x in myThreadList:
if not x.is_alive():
#print(x)
x.start()
for x in myThreadList:
x.join()
def list_sort(xxx):
fff=xxx.split(".")
return int(fff[3])
#https://www.w3schools.com/python/ref_list_sort.asp
iplist.sort(key=list_sort)
return iplist