我一直在試圖做一個python腳本,會問你一個IP,並有許多同時我應該做的PING。Python多線程「ping」
但好像我只能一次運行一個PING
我在OSX運行
import _thread
import os
import time
def main():
threadnbr = 0
ip = str(input("Input the ip adresse to play with? "))
threads = int(input("Have many threads? "))
check(ip)
if check(ip) == 0:
print("It is up")
else:
print("Is is down")
thread(ip, threads, threadnbr)
def thread(ip, threads, threadnbr):
while threads > threadnbr:
_thread.start_new_thread(dos(ip))
threadnbr = threadnbr + 1
else:
print(threadnbr, " started")
def check(ip):
response = os.system("ping -c 1 " + ip)
return response
def dos(ip):
os.system("ping -i 0.1 -s 8000 " + ip)
print("1")
main()
我學習的IT技術,以及我們對ICMP,所以是的,它是教育的目的。 但是,我應該寫程序嗎? – 2014-12-02 11:37:41
@JesperPetersen你*可能*想寫'_thread.start_new_thread(dos,(ip,))' – goncalopp 2014-12-02 11:54:09
我有沒有停止它呢? – 2014-12-02 12:08:00