Jul-11-2024, 11:33 PM
Greetings!
I’m using a subprocess to run and capture an output of the “ARP- A” command to a list.
I’d like to iterate and filter some of the IPs from the captured list but I’m failing with no errors.
If I capture the same output to a file I have no problem with filtering IPs I want.
Code:
Thank you!
I’m using a subprocess to run and capture an output of the “ARP- A” command to a list.
I’d like to iterate and filter some of the IPs from the captured list but I’m failing with no errors.
If I capture the same output to a file I have no problem with filtering IPs I want.
Code:
from pathlib import Path import subprocess import re kk = [] output = subprocess.run( ["arp", "-a"], #encoding="utf-8", capture_output=True, creationflags=subprocess.CREATE_NO_WINDOW, # Notice this is a function argument, not variable assignment ) kk.append(output.stdout.strip()) for el in kk : el=el.strip() if "192.168.1" in el : cell = re.split('\s+', el) # and so on...I understand stdout I'm capturing is in a 'wrong' format to do line by line search. I'm not sure how to get around this problem.
Thank you!