Update modules/network_tools.py
This commit is contained in:
parent
cbd8133607
commit
42dcab969d
1 changed files with 17 additions and 9 deletions
|
|
@ -1,14 +1,14 @@
|
||||||
import subprocess
|
import subprocess
|
||||||
import re
|
from modules.mtr_parser import MtrParser
|
||||||
|
|
||||||
def execute_command_streaming(method, target):
|
def execute_command_streaming(method, target):
|
||||||
commands = {
|
commands = {
|
||||||
'ping': ['ping', '-c', '4', target],
|
'ping': ['ping4', '-c', '4', '--', target],
|
||||||
'ping6': ['ping', '-c', '4', target],
|
'ping6': ['ping6', '-c', '4', '--', target],
|
||||||
'mtr': ['mtr', '-w', '-r', '-c', '10', target],
|
'mtr': ['mtr', '--raw', '-n', '-c', '10', '-4', target],
|
||||||
'mtr6': ['mtr', '-w', '-r', '-c', '10', target],
|
'mtr6': ['mtr', '--raw', '-n', '-c', '10', '-6', target],
|
||||||
'traceroute': ['traceroute', '-n', target],
|
'traceroute': ['traceroute', '-n', '-4', '--', target],
|
||||||
'traceroute6': ['traceroute', '-n', target],
|
'traceroute6': ['traceroute', '-n', '-6', '--', target],
|
||||||
}
|
}
|
||||||
|
|
||||||
if method not in commands:
|
if method not in commands:
|
||||||
|
|
@ -27,6 +27,14 @@ def execute_command_streaming(method, target):
|
||||||
universal_newlines=True
|
universal_newlines=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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, ''):
|
for line in iter(proc.stdout.readline, ''):
|
||||||
yield line
|
yield line
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue