python3.4.4怎么打代码_Python3.4:未知格式代码“x”

我对Python3中的包嗅探器有问题。在

python版本:3.4

我遵循了一些有用的教程,但不是在我的电脑上。

这段代码必须获取mac地址,将其转换为字符串,并且在main()方法中应该将目标mac、源mac和协议打印给我。在

代码:嗅探器_演示.py在import socket

import struct

import textwrap

def main():

conn = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.ntohs(3))

while True:

raw_data, addr = conn.recvfrom(65536)

# one's and zero's put to the method ehternet_frame

dest_mac, src_mac, eth_proto, data = ethernet_frame(raw_data)

print('\nEthernet Frame:')

print('Destination: {}, Source: {}, Protocol: {}'.format(dest_mac, src_mac, eth_proto))

# Unpack ethernet frame

def ethernet_frame(data):

dest_mac, src_mac, proto = struct.unpack('! 6s 6s H', data[:14])

return get_mac_addr(dest_mac), get_mac_addr(src_mac), socket.htons(proto), data[14:]

# Return properly formatted MAC address: (ie AA:BB:CC:DD:EE:FF)

def get_mac_addr(bytes_addr):

bytes_str = map('{:02x}'.format, bytes_addr)

return ':'.join(bytes_str).upper()

main()

错误是:

^{pr2}$

怎么解决?在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值