Python pcapy.open_live() Examples

The following are 30 code examples of pcapy.open_live(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pcapy , or try the search function .
Example #1
Source File: sniff.py    From d4rkc0de with GNU General Public License v2.0 7 votes vote down vote up
def main(filter):
    dev = getInterface()

    # Open interface for catpuring.
    p = open_live(dev, 1500, 0, 100)

    # Set the BPF filter. See tcpdump(3).
    p.setfilter(filter)

    print "Listening on %s: net=%s, mask=%s, linktype=%d" % (dev, p.getnet(), p.getmask(), p.datalink())

    # Start sniffing thread and finish main thread.
    DecoderThread(p).start()

# Process command-line arguments. Take everything as a BPF filter to pass
# onto pcap. Default to the empty filter (match all). 
Example #2
Source File: sniff.py    From darkc0de-old-stuff with GNU General Public License v3.0 6 votes vote down vote up
def main(filter):
    dev = getInterface()

    # Open interface for catpuring.
    p = open_live(dev, 1500, 0, 100)

    # Set the BPF filter. See tcpdump(3).
    p.setfilter(filter)

    print "Listening on %s: net=%s, mask=%s, linktype=%d" % (dev, p.getnet(), p.getmask(), p.datalink())

    # Start sniffing thread and finish main thread.
    DecoderThread(p).start()

# Process command-line arguments. Take everything as a BPF filter to pass
# onto pcap. Default to the empty filter (match all). 
Example #3
Source File: sniff.py    From Slackor with GNU General Public License v3.0 6 votes vote down vote up
def main(filter):
    dev = getInterface()

    # Open interface for catpuring.
    p = open_live(dev, 1500, 0, 100)

    # Set the BPF filter. See tcpdump(3).
    p.setfilter(filter)

    print("Listening on %s: net=%s, mask=%s, linktype=%d" % (dev, p.getnet(), p.getmask(), p.datalink()))

    # Start sniffing thread and finish main thread.
    DecoderThread(p).start()

# Process command-line arguments. Take everything as a BPF filter to pass
# onto pcap. Default to the empty filter (match all). 
Example #4
Source File: os_ident.py    From Slackor with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, target, ports):
        pcap_dev = lookupdev()
        self.p = open_live(pcap_dev, 600, 0, 3000)
        
        self.__source = self.p.getlocalip()
        self.__target = target
        
        self.p.setfilter("src host %s and dst host %s" % (target, self.__source), 1, 0xFFFFFF00)
        self.p.setmintocopy(10)
        self.decoder = EthDecoder()
        
        self.tests_sent = []
        self.outstanding_count = 0
        self.results = {}
        self.current_id = 12345

        self.__ports = ports 
Example #5
Source File: sniff.py    From PiBunny with MIT License 6 votes vote down vote up
def main(filter):
    dev = getInterface()

    # Open interface for catpuring.
    p = open_live(dev, 1500, 0, 100)

    # Set the BPF filter. See tcpdump(3).
    p.setfilter(filter)

    print "Listening on %s: net=%s, mask=%s, linktype=%d" % (dev, p.getnet(), p.getmask(), p.datalink())

    # Start sniffing thread and finish main thread.
    DecoderThread(p).start()

# Process command-line arguments. Take everything as a BPF filter to pass
# onto pcap. Default to the empty filter (match all). 
Example #6
Source File: tracer.py    From PiBunny with MIT License 6 votes vote down vote up
def start(self):
        self.p = open_live(self.interface, 1600, 0, 100)
##         self.p.setnonblock(1)
        if self.filter:
            self.p.setfilter(self.filter)

        # Query the type of the link and instantiate a decoder accordingly.
        datalink = self.p.datalink()
        if pcapy.DLT_EN10MB == datalink:
            self.decoder = EthDecoder()
        elif pcapy.DLT_LINUX_SLL == datalink:
            self.decoder = LinuxSLLDecoder()
        else:
            raise Exception("Datalink type not supported: " % datalink)

        self.tk.after(POLL_PERIOD, self.poll)
        self.tk.after(REFRESH_PERIOD, self.timerDraw);
        self.tk.bind('q',self.quit)
        self.tk.mainloop() 
Example #7
Source File: lib.py    From netscan2 with MIT License 5 votes vote down vote up
def run(self):
        pass
        # max_bytes = 1024
        # promiscuous = False
        # read_timeout = 100  # in milliseconds
        # pc = pcapy.open_live(iface, max_bytes, promiscuous, read_timeout)
        # if filter: pc.setfilter(filter)
        # self.dumper = pc.dump_open(filename)
        # pc.loop(num_packets, self.recv_pkts)  # capture packets 
Example #8
Source File: lib.py    From netscan2 with MIT License 5 votes vote down vote up
def __init__(self, iface, filename='test.pcap', pcFilter=None, num_packets=3000):
        # list all the network devices
        # print pcapy.findalldevs()

        max_bytes = 1024
        promiscuous = False
        read_timeout = 100  # in milliseconds
        pc = pcapy.open_live(iface, max_bytes, promiscuous, read_timeout)
        if pcFilter: pc.setfilter(pcFilter)
        self.dumper = pc.dump_open(filename)
        pc.loop(num_packets, self.recv_pkts)  # capture packets

    # callback for received packets 
Example #9
Source File: pcapdnet.py    From POC-EXP with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kargs):
                    self.pcap = pcap.open_live(*args, **kargs) 
Example #10
Source File: pcapdnet.py    From POC-EXP with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kargs):
                    self.pcap = pcap.pcapObject()
                    self.pcap.open_live(*args, **kargs) 
Example #11
Source File: tracer.py    From PiBunny with MIT License 5 votes vote down vote up
def getInterfaces():
    # Grab a list of interfaces that pcap is able to listen on.
    # The current user will be able to listen from all returned interfaces,
    # using open_live to open them.
    ifs = findalldevs()

    # No interfaces available, abort.
    if 0 == len(ifs):
        return "You don't have enough permissions to open any interface on this system."

    return ifs 
Example #12
Source File: sniff.py    From darkc0de-old-stuff with GNU General Public License v3.0 5 votes vote down vote up
def getInterface():
    # Grab a list of interfaces that pcap is able to listen on.
    # The current user will be able to listen from all returned interfaces,
    # using open_live to open them.
    ifs = findalldevs()

    # No interfaces available, abort.
    if 0 == len(ifs):
        print "You don't have enough permissions to open any interface on this system."
        sys.exit(1)

    # Only one interface available, use it.
    elif 1 == len(ifs):
        print 'Only one interface present, defaulting to it.'
        return ifs[0]

    # Ask the user to choose an interface from the list.
    count = 0
    for iface in ifs:
        print '%i - %s' % (count, iface)
        count += 1
    idx = int(raw_input('Please select an interface: '))

    return ifs[idx] 
Example #13
Source File: sniff.py    From PiBunny with MIT License 5 votes vote down vote up
def getInterface():
    # Grab a list of interfaces that pcap is able to listen on.
    # The current user will be able to listen from all returned interfaces,
    # using open_live to open them.
    ifs = findalldevs()

    # No interfaces available, abort.
    if 0 == len(ifs):
        print "You don't have enough permissions to open any interface on this system."
        sys.exit(1)

    # Only one interface available, use it.
    elif 1 == len(ifs):
        print 'Only one interface present, defaulting to it.'
        return ifs[0]

    # Ask the user to choose an interface from the list.
    count = 0
    for iface in ifs:
        print '%i - %s' % (count, iface)
        count += 1
    idx = int(raw_input('Please select an interface: '))

    return ifs[idx] 
Example #14
Source File: sniff.py    From Slackor with GNU General Public License v3.0 5 votes vote down vote up
def getInterface():
    # Grab a list of interfaces that pcap is able to listen on.
    # The current user will be able to listen from all returned interfaces,
    # using open_live to open them.
    ifs = findalldevs()

    # No interfaces available, abort.
    if 0 == len(ifs):
        print("You don't have enough permissions to open any interface on this system.")
        sys.exit(1)

    # Only one interface available, use it.
    elif 1 == len(ifs):
        print('Only one interface present, defaulting to it.')
        return ifs[0]

    # Ask the user to choose an interface from the list.
    count = 0
    for iface in ifs:
        print('%i - %s' % (count, iface))
        count += 1
    idx = int(input('Please select an interface: '))

    return ifs[idx] 
Example #15
Source File: nmapAnswerMachine.py    From Slackor with GNU General Public License v3.0 5 votes vote down vote up
def initPcap(self):
       self.pcap = pcapy.open_live(self.interface, 65535, 1, 0)
       try:       self.pcap.setfilter("host %s or ether host %s" % (self.ipAddress, self.macAddress))
       except:    self.pcap.setfilter("host %s or ether host %s" % (self.ipAddress, self.macAddress), 1, 0xFFFFFF00) 
Example #16
Source File: pcapdnet.py    From isip with MIT License 5 votes vote down vote up
def __init__(self, *args, **kargs):
                    self.pcap = pcap.open_live(*args, **kargs) 
Example #17
Source File: pcapdnet.py    From isip with MIT License 5 votes vote down vote up
def __init__(self, *args, **kargs):
                    self.pcap = pcap.pcapObject()
                    self.pcap.open_live(*args, **kargs) 
Example #18
Source File: sniff.py    From d4rkc0de with GNU General Public License v2.0 5 votes vote down vote up
def getInterface():
    # Grab a list of interfaces that pcap is able to listen on.
    # The current user will be able to listen from all returned interfaces,
    # using open_live to open them.
    ifs = findalldevs()

    # No interfaces available, abort.
    if 0 == len(ifs):
        print "You don't have enough permissions to open any interface on this system."
        sys.exit(1)

    # Only one interface available, use it.
    elif 1 == len(ifs):
        print 'Only one interface present, defaulting to it.'
        return ifs[0]

    # Ask the user to choose an interface from the list.
    count = 0
    for iface in ifs:
        print '%i - %s' % (count, iface)
        count += 1
    idx = int(raw_input('Please select an interface: '))

    return ifs[idx] 
Example #19
Source File: pcapdnet.py    From dash-hack with MIT License 5 votes vote down vote up
def __init__(self, *args, **kargs):
                    self.pcap = pcap.pcapObject()
                    self.pcap.open_live(*args, **kargs) 
Example #20
Source File: pcapdnet.py    From dash-hack with MIT License 5 votes vote down vote up
def __init__(self, *args, **kargs):
                    self.pcap = pcap.open_live(*args, **kargs) 
Example #21
Source File: pcapdnet.py    From dash-hack with MIT License 5 votes vote down vote up
def __init__(self, *args, **kargs):
                    self.pcap = pcap.pcapObject()
                    self.pcap.open_live(*args, **kargs) 
Example #22
Source File: pcapdnet.py    From dash-hack with MIT License 5 votes vote down vote up
def __init__(self, *args, **kargs):
                    self.pcap = pcap.open_live(*args, **kargs) 
Example #23
Source File: pcapdnet.py    From dash-hack with MIT License 5 votes vote down vote up
def __init__(self, *args, **kargs):
                    self.pcap = pcap.pcapObject()
                    self.pcap.open_live(*args, **kargs) 
Example #24
Source File: pcapdnet.py    From mptcp-abuse with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, *args, **kargs):
                    self.pcap = pcap.open_live(*args, **kargs) 
Example #25
Source File: pcapdnet.py    From mptcp-abuse with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, *args, **kargs):
                    self.pcap = pcap.pcapObject()
                    self.pcap.open_live(*args, **kargs) 
Example #26
Source File: pcapdnet.py    From CVE-2016-6366 with MIT License 5 votes vote down vote up
def __init__(self, *args, **kargs):
                    self.pcap = pcap.open_live(*args, **kargs) 
Example #27
Source File: pcapdnet.py    From CVE-2016-6366 with MIT License 5 votes vote down vote up
def __init__(self, *args, **kargs):
                    self.pcap = pcap.pcapObject()
                    self.pcap.open_live(*args, **kargs) 
Example #28
Source File: pcapdnet.py    From smod-1 with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, *args, **kargs):
                    self.pcap = pcap.open_live(*args, **kargs) 
Example #29
Source File: pcapdnet.py    From smod-1 with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, *args, **kargs):
                    self.pcap = pcap.pcapObject()
                    self.pcap.open_live(*args, **kargs) 
Example #30
Source File: udp_traffic.py    From marsnake with GNU General Public License v3.0 5 votes vote down vote up
def init(self):
        try:
            self.device = pcapy.open_live(pcapy.lookupdev(), 65535, 0, 0)
            self.device.setfilter("udp port 53")
        except Exception as e:
            print(e)
            return False
            
        return True