diff options
author | zezinho42 <lists.jjorge@free.fr> | 2020-05-24 13:04:13 +0200 |
---|---|---|
committer | zezinho42 <lists.jjorge@free.fr> | 2020-05-24 14:10:12 +0200 |
commit | 47e9e5295baebc57cee8bb7084808f836a6e57a9 (patch) | |
tree | 88efc58329a40d1d2ec0d7c82cdb09ca6eb0d4ad /src/monitor.py | |
parent | aa43db2bf5fadd095f723eb51c2247448c64faf5 (diff) | |
download | net_monitor-47e9e5295baebc57cee8bb7084808f836a6e57a9.tar net_monitor-47e9e5295baebc57cee8bb7084808f836a6e57a9.tar.gz net_monitor-47e9e5295baebc57cee8bb7084808f836a6e57a9.tar.bz2 net_monitor-47e9e5295baebc57cee8bb7084808f836a6e57a9.tar.xz net_monitor-47e9e5295baebc57cee8bb7084808f836a6e57a9.zip |
Add IPV6 connections
Diffstat (limited to 'src/monitor.py')
-rw-r--r-- | src/monitor.py | 14 |
1 files changed, 12 insertions, 2 deletions
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) |