1
0
Fork 0

Add IpPacket and handle_ip_packet

This commit is contained in:
Alex Kotov 2020-04-17 20:17:42 +05:00
parent cb299d9932
commit c91299ae3b
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
1 changed files with 14 additions and 3 deletions

17
main.py
View File

@ -7,6 +7,11 @@ import ipaddress
import json
import socket
class IpPacket:
def __init__(self, header, body):
self.header = header
self.body = body
class IpHeader:
def __init__(self, raw):
self.ver_ihl, \
@ -70,11 +75,17 @@ def main():
if proto != b'\x08\x00':
continue
ip_header = IpHeader(buf[4:28])
body = buf[28:]
ip_packet = IpPacket(IpHeader(buf[4:28]), buf[28:])
print(ip_header.src, '', ip_header.dst, 'len: %d' % ip_header.total_length)
handle_ip_packet(ip_packet, conn, tun_iface, config)
def handle_ip_packet(ip_packet, conn, tun_iface, config):
print(
ip_packet.header.src,
'',
ip_packet.header.dst,
'len: %d' % ip_packet.header.total_length,
)
if __name__ == '__main__':
main()