isit?

Jun 17

Threaded HTTP load generator:

Could add “”.join(random.sample(string.letters+string.digits, 16)) to the url to hit random urls.

import socket, time, random, string
import threading

class httpf(threading.Thread):
    def __init__(self,host,port,url,count):
        self.host=host
        self.port=port
        self.url=url
        self.count=int(count) #int(4321)
        threading.Thread.__init__(self)
       
    def run(self):
        for x in range(self.count):
            self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.sock.connect((self.host, self.port))
            print (“attempt to “+self.host+” “+self.url+” “+str(x)+”“)
            self.sock.send(“GET “+self.url+” HTTP/1.1\n”)
            time.sleep(0.1)
            self.sock.close()

if __name__==”__main__”:
    for z in range(32): #number of threads
        httpf(“host”,80,”url”,”num_of_requests”).start()