get-bridge-vids 740 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/python3
  2. #
  3. # Maximilian Wilhelm <max@sdn.clinic>
  4. # -- Fri 28 Apr 2023 08:41:13 PM CEST
  5. #
  6. import re
  7. import sys
  8. if len (sys.argv) != 2:
  9. print("Usage: get-bridge-vids IFACE", file=sys.stderr)
  10. sys.exit(1)
  11. ifname = sys.argv[1]
  12. ifstanza_re = re.compile(rf"^iface {ifname}")
  13. bridge_vid_re = re.compile(r"bridge-vids (.*)$")
  14. interfaces_fh = open("/etc/network/interfaces", "r")
  15. iface_found = False
  16. for line in interfaces_fh.readlines():
  17. line = line.strip()
  18. if line.startswith('#'):
  19. continue
  20. if iface_found:
  21. match = bridge_vid_re.search(line)
  22. if match:
  23. print (match.group(1))
  24. continue
  25. match = ifstanza_re.search(line)
  26. if match:
  27. iface_found = True