本文整理汇总了Python中Packet.Packet.tcp_src_port方法的典型用法代码示例。如果您正苦于以下问题:Python Packet.tcp_src_port方法的具体用法?Python Packet.tcp_src_port怎么用?Python Packet.tcp_src_port使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Packet.Packet
的用法示例。
在下文中一共展示了Packet.tcp_src_port方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Packet import Packet [as 别名]
# 或者: from Packet.Packet import tcp_src_port [as 别名]
def __init__(self, file_name):
self._file = open(file_name)
time.sleep(0.1)
self.pcap = dpkt.pcap.Reader(self._file)
time.sleep(0.5)
self.packets = []
for ts, buf in self.pcap:
try:
packet = Packet()
packet.time_stamp = ts
eth = dpkt.ethernet.Ethernet(buf)
src_mac = eth.src.encode("hex")
dst_mac = eth.dst.encode("hex")
packet.eth_src = ':'.join([src_mac[i:i+2] for i in range(0, len(src_mac), 2)])
packet.eth_dst = ':'.join([dst_mac[i:i+2] for i in range(0, len(dst_mac), 2)])
ip = eth.data
packet.ip_version = ip.v
if ip.v == 6:
packet.ip_src = socket.inet_ntop(socket.AF_INET6, ip.src)
packet.ip_dst = socket.inet_ntop(socket.AF_INET6, ip.dst)
if ip.v == 4:
packet.ip_src = socket.inet_ntoa(ip.src)
packet.ip_dst = socket.inet_ntoa(ip.dst)
if ip.p is dpkt.ip.IP_PROTO_TCP or ip.nxt is dpkt.ip.IP_PROTO_TCP:
tcp = ip.data
packet.tcp_src_port = tcp.sport
packet.tcp_dst_port = tcp.dport
if ip.udp is not None:
packet.udp_src_port = ip.udp.sport
packet.udp_dst_port = ip.udp.dport
except AttributeError:
pass
self.packets.append(packet)