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

checking inf down to be delete

parent 2178486b
No related branches found
No related tags found
No related merge requests found
......@@ -49,6 +49,25 @@ def add_interface_to_bridge(bridge_name, interface_name):
subprocess.run(["sudo", "brctl", "addif", bridge_name, interface_name], check=True)
def is_interface_down(interface):
"""
Check if the network interface is down.
:param interface: Name of the network interface to check
:return: True if the interface is down, False otherwise
"""
try:
result = subprocess.run(
["ip", "link", "show", interface],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
return "state DOWN" in result.stdout
except subprocess.CalledProcessError:
print(f"Failed to check status of interface {interface}.")
return False
def delete_tuntap_interface(interface_name):
"""
Delete a tuntap mode tap interface.
......@@ -58,6 +77,10 @@ def delete_tuntap_interface(interface_name):
subprocess.run(["sudo", "ip", "link", "set", "dev", interface_name, "down"], check=True)
# Delete the tuntap interface
print("Waiting for interface to be down...")
while not is_interface_down(interface_name):
pass
subprocess.run(["sudo", "ip", "tuntap", "del", interface_name, "mode", "tap"], check=True)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment