學了一下python的多線程,threading模塊python
感受挺有意思的,隨便練手寫了一個很粗陋的windows下多線程掃在線ip的腳本windows
腳本沒什麼技術含量,純粹練手,掃一趟192的局域網要花個5分多鐘...主要是由於直接用的python調用system命令去ping...多線程
# Author: 昏鴉 import os import threading def scan(lis): ip = "192.168.1.{}" for i in lis: res = ''.join(os.popen('ping -n 2 ' + ip.format(i)).readlines()) pattern = "([\d]+)% 丟失" drop = re.search(pattern,res).group(1) if '沒法訪問' in res: continue else: if int(drop)< 51: print(ip.format(i)) else: continue if __name__ == '__main__': threads = [] for i in range(5): t = threading.Thread(target=scan,args=(list(range(i*51,i*51+51)),)) threads.append(t) for t in threads: t.start() for t in threads: t.join()