minor fixes
This commit is contained in:
@@ -3,10 +3,13 @@
|
||||
|
||||
import typer
|
||||
from rich import print
|
||||
from rich.markup import escape
|
||||
from typer import Exit
|
||||
from firegex import __version__
|
||||
from firegex.nfproxy.proxysim import run_proxy_simulation
|
||||
from firegex.nfproxy.models import Protocols
|
||||
import os
|
||||
import socket
|
||||
|
||||
app = typer.Typer(
|
||||
no_args_is_help=True,
|
||||
@@ -18,6 +21,19 @@ def close_cli(code:int=1):
|
||||
|
||||
DEV_MODE = __version__ == "0.0.0"
|
||||
|
||||
def test_connection(host, port, use_ipv6=False):
|
||||
family = socket.AF_INET6 if use_ipv6 else socket.AF_INET
|
||||
sock = socket.socket(family, socket.SOCK_STREAM)
|
||||
|
||||
try:
|
||||
sock.settimeout(3)
|
||||
sock.connect((host, port))
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
finally:
|
||||
sock.close()
|
||||
|
||||
@app.command(help="Run an nfproxy simulation")
|
||||
def nfproxy(
|
||||
filter_file: str = typer.Argument(..., help="The path to the filter file"),
|
||||
@@ -31,7 +47,12 @@ def nfproxy(
|
||||
):
|
||||
if from_address is None:
|
||||
from_address = "::1" if ipv6 else "127.0.0.1"
|
||||
|
||||
if not os.path.isfile(filter_file):
|
||||
print(f"[bold red]'{escape(os.path.abspath(filter_file))}' not found[/]")
|
||||
close_cli()
|
||||
if not test_connection(address, port, ipv6):
|
||||
print(f"[bold red]Can't connect to {escape(address)}:{port}[/]")
|
||||
close_cli()
|
||||
run_proxy_simulation(filter_file, proto.value, address, port, from_address, from_port, ipv6)
|
||||
|
||||
def version_callback(verison: bool):
|
||||
|
||||
Reference in New Issue
Block a user