예제 #1
0
 def wait_for_complete(self):
     # ...then, wait for each of them to terminate:
     while len(self.workers):
         worker = self.workers.pop()
         worker.join()
         if worker.isAlive() and not self.workQueue.empty():
             self.workers.append(worker)
     pool_log.log_info("All jobs are are completed.")
예제 #2
0
 def run(self):
     ''' the get-some-work, do-some-work main loop of worker threads '''
     while True:
         try:
             callable, args, kwds = self.workQueue.get(timeout=self.timeout)
             res = callable(*args, **kwds)
             pool_log.log_info("worker[%2d]: %s" % (self.id, str(res)))
             self.resultQueue.put(res)
         except Queue.Empty:
             break
         except:
             pool_log.log_info('worker[%2d]' % self.id, sys.exc_info()[:2])
예제 #3
0
def send_request(request):
    try:
        response = urllib2.urlopen(request)
        code = response.getcode()
        pool_log.log_info("response code %s" % code)
        if (code == 302):
            redirect_url = response.geturl()
            pool_log.log_info("redirect to %s" % redirect_url)
            redirect_request = urllib2.Request(redirect_url)
            response = urllib2.urlopen(redirect_request)
    except Exception, e:
        error_str = "send request exception ,%s" % e
        pool_log.log_error(error_str)
예제 #4
0
def main_pcap(p_time, p_data, local_ip, port, resent_ip, count):
    p = dpkt.ethernet.Ethernet(p_data)
    if p.type == dpkt.ethernet.ETH_TYPE_IP:
        ip_data = p.data
        src_ip = '%d.%d.%d.%d' % tuple(map(ord, list(ip_data.src)))
        dst_ip = '%d.%d.%d.%d' % tuple(map(ord, list(ip_data.dst)))
        if ip_data.p == dpkt.ip.IP_PROTO_UDP:
            udp_data = p.data.data
            if udp_data.data:
                try:
                    pool_log.log_info("get data: %s" % udp_data.data)
                    data = eval(udp_data.data)
                    pool.pool_data(data, resent_ip, count)
                except Exception, e:
                    error_str = "Capture src_ip %s:local_ip %s:dst_ip %s:exception: %s" % (
                        src_ip, local_ip, dst_ip, e)
                    pool_log.log_error(error_str)
예제 #5
0
def start():
    if (len(sys.argv) < 3):
        capture_nc = pool_config.getConfig("config", 'nc')
        if (not capture_nc):
            print "error not have network card info"
            pool_log.error_log("error not have network card info")
            sys.exit(1)
        resent_ip = pool_config.getConfig("config", 'resent_ip')
        if (not resent_ip):
            print "error not have resent ip info"
            pool_log.error_log("error not have resent ip info")
            sys.exit(1)
        print "Start sender sever network card: %s resent ip: %s" % (
            capture_nc, resent_ip)
        pool_log.log_info("Start sender sever network card: %s resent ip: %s" %
                          (capture_nc, resent_ip))
        count = pool_config.getConfig("config", 'count')
        port = pool_config.getConfig("config", 'port')
        if (count):
            if (port):
                capture_udp.capture(capture_nc, resent_ip, count, int(port))
            else:
                capture_udp.capture(capture_nc, resent_ip, count)
        else:
            capture_udp.capture(capture_nc, resent_ip)
    else:
        capture_nc = sys.argv[1]
        resent_ip = sys.argv[2]
        print "Start pool sever network card: %s resent ip: %s" % (capture_nc,
                                                                   resent_ip)
        if (len(sys.argv) == 4):
            count = sys.argv[3]
            capture_udp.capture(capture_nc, resent_ip, count)
        elif (len(sys.argv) == 5):
            count = sys.argv[3]
            port = sys.argv[4]
            capture_udp.capture(capture_nc, resent_ip, count, port)
        else:
            capture_udp.capture(capture_nc, resent_ip)
예제 #6
0
def wapper_data(data, resent_ip, count):
    uri = data['uri']
    data_headers = None
    if (data.has_key('headers')):
        data_headers = data['headers']
        pool_log.log_debug("request headers %s" % data_headers)
    port = data["port"]
    url = "http://%s:%s%s" % (resent_ip, port, uri)
    pool_log.log_info("request url %s" % url)
    request = None
    # add body
    if (cmp(data['method'], "GET") == 0):
        request = urllib2.Request(url)
    elif (cmp(data['method'], "POST") == 0):
        get_body = data['body']
        message = "request body %s" % get_body
        pool_log.log_debug(message)
        request = urllib2.Request(url, str(get_body))
    # add header
    if (request and data_headers):
        for key, value in data_headers.iteritems():
            request.add_header(key, value)
    return request
예제 #7
0
def stop_in_pool(message):
    pool_log.log_info(message)
    in_flag = False
예제 #8
0
def start_pool_send(message):
    pool_log.log_info(message)
    wm.wait_for_complete()