From c91299ae3bfd9deff324a6214eaefa6849043d4f Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Fri, 17 Apr 2020 20:17:42 +0500 Subject: [PATCH] Add IpPacket and handle_ip_packet --- main.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index b73fc4c..ad7a04a 100755 --- a/main.py +++ b/main.py @@ -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()