本文整理汇总了Python中pcapy.open_live方法的典型用法代码示例。如果您正苦于以下问题:Python pcapy.open_live方法的具体用法?Python pcapy.open_live怎么用?Python pcapy.open_live使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pcapy
的用法示例。
在下文中一共展示了pcapy.open_live方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getInterface
# 需要导入模块: import pcapy [as 别名]
# 或者: from pcapy import open_live [as 别名]
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]
示例2: main
# 需要导入模块: import pcapy [as 别名]
# 或者: from pcapy import open_live [as 别名]
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).
示例3: getInterface
# 需要导入模块: import pcapy [as 别名]
# 或者: from pcapy import open_live [as 别名]
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]
示例4: main
# 需要导入模块: import pcapy [as 别名]
# 或者: from pcapy import open_live [as 别名]
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).
示例5: __init__
# 需要导入模块: import pcapy [as 别名]
# 或者: from pcapy import open_live [as 别名]
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
示例6: start
# 需要导入模块: import pcapy [as 别名]
# 或者: from pcapy import open_live [as 别名]
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()
示例7: __init__
# 需要导入模块: import pcapy [as 别名]
# 或者: from pcapy import open_live [as 别名]
def __init__(self, *args, **kargs):
self.pcap = pcap.open_live(*args, **kargs)
示例8: init
# 需要导入模块: import pcapy [as 别名]
# 或者: from pcapy import open_live [as 别名]
def init(self):
try:
self.device = pcapy.open_live(pcapy.lookupdev(), 65535, 0, 0)
self.device.setfilter("tcp port 80")
except Exception as e:
print(e)
return False
return True
示例9: init
# 需要导入模块: import pcapy [as 别名]
# 或者: from pcapy import open_live [as 别名]
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
示例10: __init__
# 需要导入模块: import pcapy [as 别名]
# 或者: from pcapy import open_live [as 别名]
def __init__(self, *args, **kargs):
self.pcap = pcap.pcapObject()
self.pcap.open_live(*args, **kargs)
示例11: initPcap
# 需要导入模块: import pcapy [as 别名]
# 或者: from pcapy import open_live [as 别名]
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)
示例12: __init__
# 需要导入模块: import pcapy [as 别名]
# 或者: from pcapy import open_live [as 别名]
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