Python pcapy.pcap() Examples

The following are 30 code examples of pcapy.pcap(). 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: pcapdnet.py    From CyberScan with GNU General Public License v3.0 6 votes vote down vote up
def setfilter(self, filter):
                    self.pcap.setfilter(filter, 0, 0) 
Example #2
Source File: pcapdnet.py    From CyberScan with GNU General Public License v3.0 6 votes vote down vote up
def next(self):
                    c = self.pcap.next()
                    if c is None:
                        return
                    l,pkt,ts = c 
                    return ts,pkt 
Example #3
Source File: pcapdnet.py    From dash-hack with MIT License 5 votes vote down vote up
def next(self):
                    c = self.pcap.next()
                    if c is None:
                        return
                    ts, pkt = c
                    return ts, str(pkt) 
Example #4
Source File: pcapdnet.py    From isip with MIT License 5 votes vote down vote up
def next(self):
                    c = self.pcap.next()
                    if c is None:
                        return
                    l,pkt,ts = c 
                    return ts,pkt 
Example #5
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 #6
Source File: pcapdnet.py    From isip with MIT License 5 votes vote down vote up
def setfilter(self, filter):
                    self.pcap.setfilter(filter, 0, 0) 
Example #7
Source File: pcapdnet.py    From isip with MIT License 5 votes vote down vote up
def __init__(self, device, snaplen, promisc, to_ms):
                    try:
                        self.pcap = pcap.pcap(device, snaplen, promisc, immediate=1, timeout_ms=to_ms)
                    except TypeError:
                        # Older pypcap versions do not support the timeout_ms argument
                        self.pcap = pcap.pcap(device, snaplen, promisc, immediate=1) 
Example #8
Source File: pcapdnet.py    From dash-hack with MIT License 5 votes vote down vote up
def __init__(self, iface = None, type = ETH_P_ALL, filter=None, nofilter=0):
            if iface is None:
                iface = conf.iface
            self.iface = iface
            self.ins = open_pcap(iface, 1600, 0, 100)
            try:
                ioctl(self.ins.fileno(),BIOCIMMEDIATE,struct.pack("I",1))
            except:
                pass
            if nofilter:
                if type != ETH_P_ALL:  # PF_PACKET stuff. Need to emulate this for pcap
                    filter = "ether proto %i" % type
                else:
                    filter = None
            else:
                if conf.except_filter:
                    if filter:
                        filter = "(%s) and not (%s)" % (filter, conf.except_filter)
                    else:
                        filter = "not (%s)" % conf.except_filter
                if type != ETH_P_ALL:  # PF_PACKET stuff. Need to emulate this for pcap
                    if filter:
                        filter = "(ether proto %i) and (%s)" % (type,filter)
                    else:
                        filter = "ether proto %i" % type
            if filter:
                self.ins.setfilter(filter)
            self.outs = dnet.eth(iface) 
Example #9
Source File: pcapdnet.py    From dash-hack with MIT License 5 votes vote down vote up
def __init__(self, type = ETH_P_ALL, filter=None, promisc=None, iface=None, nofilter=0):
            self.iflist = {}
            self.intf = dnet.intf()
            if iface is None:
                iface = conf.iface
            self.iface = iface
            self.ins = open_pcap(iface, 1600, 0, 100)
            try:
                ioctl(self.ins.fileno(),BIOCIMMEDIATE,struct.pack("I",1))
            except:
                pass
            if nofilter:
                if type != ETH_P_ALL:  # PF_PACKET stuff. Need to emulate this for pcap
                    filter = "ether proto %i" % type
                else:
                    filter = None
            else:
                if conf.except_filter:
                    if filter:
                        filter = "(%s) and not (%s)" % (filter, conf.except_filter)
                    else:
                        filter = "not (%s)" % conf.except_filter
                if type != ETH_P_ALL:  # PF_PACKET stuff. Need to emulate this for pcap
                    if filter:
                        filter = "(ether proto %i) and (%s)" % (type,filter)
                    else:
                        filter = "ether proto %i" % type
            if filter:
                self.ins.setfilter(filter) 
Example #10
Source File: pcapdnet.py    From dash-hack with MIT License 5 votes vote down vote up
def __getattr__(self, attr):
                    return getattr(self.pcap, attr) 
Example #11
Source File: pcapdnet.py    From isip with MIT License 5 votes vote down vote up
def __getattr__(self, attr):
                    return getattr(self.pcap, attr) 
Example #12
Source File: pcapdnet.py    From dash-hack with MIT License 5 votes vote down vote up
def next(self):
                    try:
                        c = self.pcap.next()
                    except pcap.PcapError:
                        return None
                    else:
                        h,p = c
                        s,us = h.getts()
                        return (s+0.000001*us), p 
Example #13
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 #14
Source File: pcapdnet.py    From dash-hack with MIT License 5 votes vote down vote up
def __del__(self):
                    fd = self.pcap.fileno()
                    os.close(fd) 
Example #15
Source File: pcapdnet.py    From dash-hack with MIT License 5 votes vote down vote up
def __getattr__(self, attr):
                    return getattr(self.pcap, attr) 
Example #16
Source File: pcapdnet.py    From dash-hack with MIT License 5 votes vote down vote up
def next(self):
                    c = self.pcap.next()
                    if c is None:
                        return
                    l,pkt,ts = c 
                    return ts,pkt 
Example #17
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 #18
Source File: pcapdnet.py    From dash-hack with MIT License 5 votes vote down vote up
def __init__(self, iface = None, type = ETH_P_ALL, filter=None, nofilter=0):
            if iface is None:
                iface = conf.iface
            self.iface = iface
            self.ins = open_pcap(iface, 1600, 0, 100)
            try:
                ioctl(self.ins.fileno(),BIOCIMMEDIATE,struct.pack("I",1))
            except:
                pass
            if nofilter:
                if type != ETH_P_ALL:  # PF_PACKET stuff. Need to emulate this for pcap
                    filter = "ether proto %i" % type
                else:
                    filter = None
            else:
                if conf.except_filter:
                    if filter:
                        filter = "(%s) and not (%s)" % (filter, conf.except_filter)
                    else:
                        filter = "not (%s)" % conf.except_filter
                if type != ETH_P_ALL:  # PF_PACKET stuff. Need to emulate this for pcap
                    if filter:
                        filter = "(ether proto %i) and (%s)" % (type,filter)
                    else:
                        filter = "ether proto %i" % type
            if filter:
                self.ins.setfilter(filter)
            self.outs = dnet.eth(iface) 
Example #19
Source File: pcapdnet.py    From dash-hack with MIT License 5 votes vote down vote up
def __getattr__(self, attr):
                    return getattr(self.pcap, attr) 
Example #20
Source File: pcapdnet.py    From dash-hack with MIT License 5 votes vote down vote up
def __init__(self, device, snaplen, promisc, to_ms):
                    try:
                        self.pcap = pcap.pcap(device, snaplen, promisc, immediate=1, timeout_ms=to_ms)
                    except TypeError:
                        # Older pypcap versions do not support the timeout_ms argument
                        self.pcap = pcap.pcap(device, snaplen, promisc, immediate=1) 
Example #21
Source File: pcapdnet.py    From dash-hack with MIT License 5 votes vote down vote up
def __init__(self, iface = None, type = ETH_P_ALL, filter=None, nofilter=0):
            if iface is None:
                iface = conf.iface
            self.iface = iface
            self.ins = open_pcap(iface, 1600, 0, 100)
            try:
                ioctl(self.ins.fileno(),BIOCIMMEDIATE,struct.pack("I",1))
            except:
                pass
            if nofilter:
                if type != ETH_P_ALL:  # PF_PACKET stuff. Need to emulate this for pcap
                    filter = "ether proto %i" % type
                else:
                    filter = None
            else:
                if conf.except_filter:
                    if filter:
                        filter = "(%s) and not (%s)" % (filter, conf.except_filter)
                    else:
                        filter = "not (%s)" % conf.except_filter
                if type != ETH_P_ALL:  # PF_PACKET stuff. Need to emulate this for pcap
                    if filter:
                        filter = "(ether proto %i) and (%s)" % (type,filter)
                    else:
                        filter = "ether proto %i" % type
            if filter:
                self.ins.setfilter(filter)
            self.outs = dnet.eth(iface) 
Example #22
Source File: pcapdnet.py    From dash-hack with MIT License 5 votes vote down vote up
def __getattr__(self, attr):
                    return getattr(self.pcap, attr) 
Example #23
Source File: pcapdnet.py    From dash-hack with MIT License 5 votes vote down vote up
def next(self):
                    try:
                        c = self.pcap.next()
                    except pcap.PcapError:
                        return None
                    else:
                        h,p = c
                        s,us = h.getts()
                        return (s+0.000001*us), p 
Example #24
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 #25
Source File: pcapdnet.py    From dash-hack with MIT License 5 votes vote down vote up
def __del__(self):
                    fd = self.pcap.fileno()
                    os.close(fd) 
Example #26
Source File: pcapdnet.py    From dash-hack with MIT License 5 votes vote down vote up
def __getattr__(self, attr):
                    return getattr(self.pcap, attr) 
Example #27
Source File: pcapdnet.py    From dash-hack with MIT License 5 votes vote down vote up
def setfilter(self, filter):
                    self.pcap.setfilter(filter, 0, 0) 
Example #28
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 #29
Source File: pcapdnet.py    From dash-hack with MIT License 5 votes vote down vote up
def next(self):
                    c = self.pcap.next()
                    if c is None:
                        return
                    ts, pkt = c
                    return ts, str(pkt) 
Example #30
Source File: pcapdnet.py    From dash-hack with MIT License 5 votes vote down vote up
def __getattr__(self, attr):
                    return getattr(self.pcap, attr)