def make_header(self, source_ip, destination_ip, data_len, transport_protocol_len, transport_protocol, ttl=64):
srcip = inet_aton(source_ip) # Source port
dstip = inet_aton(destination_ip) # Destination port
ver = 4 # IP protocol version
ihl = 5 # Internet Header Length
dscp_ecn = 0 # Differentiated Services Code Point and Explicit Congestion Notification
tlen = data_len + transport_protocol_len + 20 # Packet length
ident = htons(randint(1, 65535)) # Identification
flg_frgoff = 0 # Flags and fragmentation offset
ptcl = transport_protocol # Protocol
chksm = 0 # Checksum
ip_header = pack("!" "2B" "3H" "2B" "H" "4s" "4s",
(ver << 4) + ihl, dscp_ecn, tlen, ident,
flg_frgoff, ttl, ptcl, chksm, srcip, dstip)
chksm = self.checksum(ip_header)
return pack("!" "2B" "3H" "2B" "H" "4s" "4s",
(ver << 4) + ihl, dscp_ecn, tlen, ident,
flg_frgoff, ttl, ptcl, chksm, srcip, dstip)
评论列表
文章目录