查看我自己的以太网原始连接与wireshark和python



我试图在以太网协议下发送一条消息,但我不知道如何继续。我想用以太网向我自己的计算机发送消息,我想检查与 Wireshark 的消息交换,但我看不到有关我的通信的任何信息。我的错在哪里,或者我错过了什么?关于如何解决此问题的任何想法?

from socket import *
from fcntl import ioctl

import fcntl, struct

s=socket(AF_PACKET, SOCK_RAW)
s.bind(("enp2s0",0))

def get_mac(ifname):
s = socket(AF_INET, SOCK_DGRAM)
info = ioctl(s.fileno(), 0x8927, struct.pack('256s', bytes(ifname[:15], "ascii")))
return info[18:24]
src = get_mac("enp2s0")
print(src)
src_addr = "xb8xecxa3x80xebxb4"
payload = ("["*30)+"MESSAGE"+("]"*30)
checksum = "x1ax2bx3cx4d"
ethertype = "x88x92" #0x8892 profinet protocole


print((src_addr+src_addr+ethertype+payload+checksum).encode('utf-8'))
s.send((src_addr+src_addr+ethertype+payload+checksum).encode("utf-8"))

首先,您的代码必须以管理员权限运行(Linux 上的 sudo 或 su(。然后,通过运行代码,此回溯会出现错误:

Traceback (most recent call last):
File "eth.py", line 15, in <module>
src = get_mac("enp2s0")
File "eth.py", line 12, in get_mac
info = ioctl(s.fileno(), 0x8927, struct.pack('256s', bytes(ifname[:15], "ascii")))
TypeError: str() takes at most 1 argument (2 given)

它发现第 12 行有一个错误,更准确地说是bytes(ifname[:15],"ascii")你能提供你的输出吗?

最新更新