我最近一直在做一个原始数据包的程序。我们最近有一个关于生包的讲座,所以我一直在努力学习和做我的教授告诉我的事情。我的程序有问题,它出现了一个错误,说目标地址是必需的,它是原始的,所以我不想做socket.connect(destaddr),即使这样可以修复错误。这是我的代码:
下面是类和函数:#not real mac address to protect privacy also removed preamble
class packet(object):
b = ""
def __init__(self, payload):
self.payload = payload
def ether(self):
#preamble = "55555555555555D5"
macdest = "123456789101" #my mac address - needed to remove colons
macsource = "123456789101" #router mac address without colons
ethertype = "0800" #removed 0x because it is not needed
fcs = "" #frame check sequence none so far
frame = macdest+macsource+ethertype
return frame
def ip(self): #in hexadecimal
version = "4" #ipv4 hex