Python 多線程C段掃描、檢測 Ping掃描腳本的實(shí)現(xiàn)
我就廢話不多說了,大家還是直接看代碼吧~
import subprocess as pimport timeimport threadingfrom queue import Queuedef check_ip(ip): w=p.Popen(’ping -n 2 ’+ip,shell=True,stdout=p.PIPE,stderr=p.PIPE,encoding=’gbk’) result=w.stdout.read() # print(result) if ’TTL’ in result:print(ip,’is Up’)def main(): q=Queue() threads=[] threads_count=255 ips = ’39.156.69.’ for i in range(1,255): q.put(ips+str(i)) # print(q.get()) for i in range(threads_count): t=threading.Thread(target=check_ip,args=(q.get(),)) t.start() threads.append(t) time.sleep(0.2) for i in threads: i.join() print(’all done’)if __name__ == ’__main__’: main()
補(bǔ)充知識:python并發(fā)掃描存活主機(jī)
看代碼吧~
import subprocessimport osimport time def ping(host): rc=subprocess.call(’ping -c2 %s &> /dev/null’ % host,shell=True) if rc == 0: print(’%s:up’% host) else: print(’%s:down’% host)if __name__ == ’__main__’: ips=[’176.130.10.%s’ % i for i in range(1,255)] for i in ips: pid=os.fork() if pid==0: ping(i) exit(0)
以上這篇Python 多線程C段掃描、檢測 Ping掃描腳本的實(shí)現(xiàn)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. python 實(shí)現(xiàn)rolling和apply函數(shù)的向下取值操作2. CSS代碼檢查工具stylelint的使用方法詳解3. 淺談python多線程和多線程變量共享問題介紹4. Python如何批量獲取文件夾的大小并保存5. vue3?Error:Unknown?variable?dynamic?import:?../views/的解決方案6. python利用platform模塊獲取系統(tǒng)信息7. react axios 跨域訪問一個或多個域名問題8. Python的Tqdm模塊實(shí)現(xiàn)進(jìn)度條配置9. Python 多線程之threading 模塊的使用10. WML語言的基本情況
