I run the code:
from subprocess import Popen, PIPE
p1 = Popen(['ip', 'addr'], stdout=PIPE)
p2 = Popen(['grep', 'enp'], stdin=p1.stdout, stdout=PIPE)
p1.stdout.close()
output=p2.communicate()[0]
print(output)
and I get the output:
b'7: enp0s20f0u1c4i2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000\n inet 172.20.10.2/28 brd 172.20.10.15 scope global dynamic enp0s20f0u1c4i2\n'
How to extract the characters enp0s20f0u1c4i2 from the string of this output?
output.split(':')[1].strip()output.split()[-1].strip()