Exemple #1
0
def filter_host(host):
    reg_host = capture_config.getConfig("filter", "host")
    if not host:
        return True
    else:
        if not reg_match(reg_host, host):
            return False
        else:
            return True
Exemple #2
0
def filter_uri(uri):
    reg_uri = capture_config.getConfig("filter", "uri")
    if not reg_uri:
        return True
    else:
        if not reg_match(reg_uri, uri):
            return False
        else:
            return True
def start():

    if (len(sys.argv) < 4):
        capture_nc = capture_config.getConfig("config", 'nc')
        if (not capture_nc):
            print "error not have network card info"
            capture_log.log_error("error not have network card info")
            sys.exit(1)
        capture_port = capture_config.getConfig("config", 'capture_port')
        if (not capture_port):
            print "error not have capture port info"
            capture_log.log_error("error not have capture port info")
            sys.exit(1)
        copy_ip = capture_config.getConfig("config", 'copy_ip')
        if (not copy_ip):
            print "error not have copyserver ip info"
            capture_log.log_error("error not have copyserver ip info")
            sys.exit(1)
        print "Start capture port: %s network card: %s copy ip: %s" % (
            capture_port, capture_nc, copy_ip)
        capture_log.log_info(
            "Start capture port: %s network card: %s copy ip: %s" %
            (capture_port, capture_nc, copy_ip))
        copy_port = capture_config.getConfig("config", 'copy_port')
        if (copy_port):
            capture.capture(capture_nc, int(capture_port), copy_ip,
                            int(copy_port))
        else:
            capture.capture(capture_nc, int(capture_port), copy_ip)
    else:
        capture_nc = sys.argv[1]
        capture_port = int(sys.argv[2])
        copy_ip = sys.argv[3]
        print "Start capture port: %s network card: %s copy ip: %s" % (
            capture_port, capture_nc, copy_ip)
        if (len(sys.argv) == 5):
            copy_port = sys.argv[4]
            capture.capture(capture_nc, capture_port, copy_ip, copy_port)
        else:
            capture.capture(capture_nc, capture_port, copy_ip)
Exemple #4
0
def capture(nc, port, copy_ip, copy_port=65533):
    try:
        local_ip = get_local_ip(nc)
        exclude_ips = capture_config.getConfig("exclude", 'ip')
        # eth1
        pc = pcap.pcap(name="%s" % nc)
        # tcp port 80
        pc.setfilter('tcp port %d' % port)
        for p_time, p_data in pc:
            main_pcap(p_time, p_data, local_ip, port, copy_ip, copy_port,
                      exclude_ips)
    except Exception, e:
        error_str = "Capture network %s:port %s:copy_ip %s: copy_port %s:exception: %s" % (
            nc, port, copy_ip, copy_port, e)
        print error_str
        sys.exit(1)
Exemple #5
0
'''
Created on 2015

@author: 14020107
'''
import capture_config

exclude_ip = capture_config.getConfig("exclude", 'ip')

def exclude_ip(src_ip):
    flag =True
    if(exclude_ip):
        exclude_ips=exclude_ip.split(',')
        for exclude in exclude_ips:
            if(cmp(src_ip, exclude) == 0):
                  flag=False     
    return flag

if __name__ == '__main__':
        #start() 
    capture_nc=capture_config.getConfig("config", 'nc')
    copy_ip=capture_config.getConfig("config", 'copy_ip')
    print "capture_nc %s " % capture_nc
    if(not copy_ip):
        print "copy_ip %s " % copy_ip
        
    print exclude_ip('192.168.1.3')