Update modules/network_tools.py

This commit is contained in:
Blackwhitebear8 2025-08-14 17:54:58 +02:00
parent cbd8133607
commit 42dcab969d

View file

@ -1,14 +1,14 @@
import subprocess
import re
from modules.mtr_parser import MtrParser
def execute_command_streaming(method, target):
commands = {
'ping': ['ping', '-c', '4', target],
'ping6': ['ping', '-c', '4', target],
'mtr': ['mtr', '-w', '-r', '-c', '10', target],
'mtr6': ['mtr', '-w', '-r', '-c', '10', target],
'traceroute': ['traceroute', '-n', target],
'traceroute6': ['traceroute', '-n', target],
'ping': ['ping4', '-c', '4', '--', target],
'ping6': ['ping6', '-c', '4', '--', target],
'mtr': ['mtr', '--raw', '-n', '-c', '10', '-4', target],
'mtr6': ['mtr', '--raw', '-n', '-c', '10', '-6', target],
'traceroute': ['traceroute', '-n', '-4', '--', target],
'traceroute6': ['traceroute', '-n', '-6', '--', target],
}
if method not in commands:
@ -27,8 +27,16 @@ def execute_command_streaming(method, target):
universal_newlines=True
)
for line in iter(proc.stdout.readline, ''):
yield line
if 'mtr' in method:
parser = MtrParser()
for line in iter(proc.stdout.readline, ''):
if line.strip():
parser.update(line)
table = parser.render_table()
yield f"@@@{table}"
else:
for line in iter(proc.stdout.readline, ''):
yield line
proc.stdout.close()
proc.wait()