From 47e9e5295baebc57cee8bb7084808f836a6e57a9 Mon Sep 17 00:00:00 2001 From: zezinho42 Date: Sun, 24 May 2020 13:04:13 +0200 Subject: Add IPV6 connections --- src/monitor.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/monitor.py b/src/monitor.py index ef8146d..4c4b5ef 100644 --- a/src/monitor.py +++ b/src/monitor.py @@ -4,6 +4,7 @@ import os import os.path import socket +import sys import fcntl import struct import traceback @@ -350,9 +351,18 @@ class Monitor: status=fields[3] loc_a,loc_p = loc.split(":") rem_a,rem_p = rem.split(":") - loc_addr = socket.inet_ntoa(struct.pack('I', int(loc_a, 16))) + if ( proto.find('6') != -1 ): + # the bytes must be reversed as IPV6 is four 32 bits blocks + loc_a = loc_a[24:32] + loc_a[16:24] + loc_a[8:16] + loc_a[0:8] + loc_a = int(loc_a, 16) + rem_a = rem_a[24:32] + rem_a[16:24] + rem_a[8:16] + rem_a[0:8] + rem_a = int(rem_a, 16) + loc_addr = socket.inet_ntop(socket.AF_INET6, loc_a.to_bytes(16, sys.byteorder)) + rem_addr = socket.inet_ntop(socket.AF_INET6, rem_a.to_bytes(16, sys.byteorder)) + else: + loc_addr = socket.inet_ntop(socket.AF_INET, struct.pack('I', int(loc_a, 16))) + rem_addr = socket.inet_ntop(socket.AF_INET, struct.pack('I', int(rem_a, 16))) loc_port = (int(loc_p, 16)) - rem_addr = socket.inet_ntoa(struct.pack('I', int(rem_a, 16))) rem_port = (int(rem_p, 16)) # parse status status = int(status, 16) -- cgit v1.2.1