2022-08-01 06:16:36 +00:00
|
|
|
from ssh_helper import HostClient
|
|
|
|
|
|
|
|
|
2022-10-09 20:01:59 +00:00
|
|
|
# TODO: convert to shell from hosting
|
2022-08-01 06:16:36 +00:00
|
|
|
class IpTablesHelper:
|
|
|
|
@staticmethod
|
|
|
|
def drop_input_traffic_to_port(client: HostClient, ports: list[str]):
|
|
|
|
for port in ports:
|
2022-09-28 12:07:16 +00:00
|
|
|
cmd_output = client.exec(cmd=f"sudo iptables -A INPUT -p tcp --dport {port} -j DROP")
|
2022-08-01 06:16:36 +00:00
|
|
|
assert cmd_output.rc == 0
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def restore_input_traffic_to_port(client: HostClient, ports: list[str]):
|
|
|
|
for port in ports:
|
2022-09-28 12:07:16 +00:00
|
|
|
cmd_output = client.exec(cmd=f"sudo iptables -D INPUT -p tcp --dport {port} -j DROP")
|
2022-08-01 06:16:36 +00:00
|
|
|
assert cmd_output.rc == 0
|