fork download
  1. text = """VirtualFuncEthernet0/7/0.2001 (up):
  2. L3 1.1.2.2/24 ip4 table-id 8 fib-idx 2
  3. L3 2001:db8:0:1:1:1:2:2/112 ip6 table-id 8 fib-idx 1
  4. VirtualFuncEthernet0/9/0 (dn):
  5. host-vpp1out (up):
  6. L3 1.1.1.1/24
  7. L3 1.1.2.1/24
  8. L3 2001:db8:0:1:1:1:1:1/112
  9. L3 2001:db8:0:1:1:1:2:1/112
  10. local0 (dn):
  11. loop0 (up):
  12. L3 1.1.1.1/32 ip4 table-id 7 fib-idx 1"""
  13.  
  14. results = []
  15. f = iter(text.splitlines())
  16. for line in f:
  17. if line.startswith("host-vpp1out (up):"):
  18. line = next(f)
  19. while line.startswith(" L3 "):
  20. results.append(line[5:].split("/")[0])
  21. line = next(f)
  22. break
  23.  
  24. print(results)
Success #stdin #stdout 0.02s 9176KB
stdin
Standard input is empty
stdout
['1.1.1.1', '1.1.2.1', '2001:db8:0:1:1:1:1:1', '2001:db8:0:1:1:1:2:1']