Skip to content
Snippets Groups Projects
Commit a2f5c6e5 authored by NGUYEN Do Duc Anh's avatar NGUYEN Do Duc Anh
Browse files

fix bug add rule

parent 3ce37a0c
No related branches found
No related tags found
No related merge requests found
......@@ -66,19 +66,20 @@ def process_packet(new_packet):
def main():
for i in range(MIN_INTER_NUMBER, MAX_INTER_NUMBER):
inter_name = MARK_TO_INTERFACE[i]
rule_1 = f"sudo iptables -t mangle -A PREROUTING -i {inter_name} -j MARK --set-mark {i}"
rule_check = "sudo iptables -C FORWARD -p tcp -j NFQUEUE --queue-num 1"
rule_2 = "sudo iptables -I FORWARD -p tcp -j NFQUEUE --queue-num 1"
try:
subprocess.run(rule_check, shell=True, check=True)
print("Rule already exists, no need to add it.")
except subprocess.CalledProcessError:
try:
rule_1 = "sudo iptables -I FORWARD -p tcp -j NFQUEUE --queue-num 1"
subprocess.run(rule_1, shell=True, check=True)
for i in range(MIN_INTER_NUMBER, MAX_INTER_NUMBER):
inter_name = MARK_TO_INTERFACE[i]
rule_2 = f"sudo iptables -t mangle -A PREROUTING -i {inter_name} -j MARK --set-mark {i}"
subprocess.run(rule_2, shell=True, check=True)
print("Rule added successfully.")
except subprocess.CalledProcessError as e:
print(f"Failed to add the rule: {e}")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment