Python 多線程C段掃描、檢測 Ping掃描腳本的實現(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()
補充知識:python并發(fā)掃描存活主機
看代碼吧~
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掃描腳本的實現(xiàn)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。
相關文章:
1. XML在語音合成中的應用2. ASP基礎入門第四篇(腳本變量、函數(shù)、過程和條件語句)3. jscript與vbscript 操作XML元素屬性的代碼4. HTTP協(xié)議常用的請求頭和響應頭響應詳解說明(學習)5. .NET Framework各版本(.NET2.0 3.0 3.5 4.0)區(qū)別6. HTML5實戰(zhàn)與剖析之觸摸事件(touchstart、touchmove和touchend)7. XML入門的常見問題(三)8. php使用正則驗證密碼字段的復雜強度原理詳細講解 原創(chuàng)9. 不要在HTML中濫用div10. ASP將數(shù)字轉中文數(shù)字(大寫金額)的函數(shù)
