Sep-08-2021, 12:33 PM
hi,
i'm parsing ifconfig output and failed to get rid of the double dot after the interface name (en0: for example). anyone?
i'm parsing ifconfig output and failed to get rid of the double dot after the interface name (en0: for example). anyone?
>>> print(ifconfig_output)
en0: flags=1e084863,18c0<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST,GROUPRT,64BIT,CHECKSUM_OFFLOAD(ACTIVE),LARGESEND,CHAIN>
inet 172.16.84.106 netmask 0xffffc000 broadcast 172.16.127.255
tcp_sendspace 262144 tcp_recvspace 262144 rfc1323 1
en1: flags=1e084863,18c0<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST,GROUPRT,64BIT,CHECKSUM_OFFLOAD(ACTIVE),LARGESEND,CHAIN>
inet 172.17.8.4 netmask 0xfffff800 broadcast 172.17.15.255
tcp_sendspace 262144 tcp_recvspace 262144 rfc1323 1
lo0: flags=e08084b,c0<UP,BROADCAST,LOOPBACK,RUNNING,SIMPLEX,MULTICAST,GROUPRT,64BIT,LARGESEND,CHAIN>
inet 127.0.0.1 netmask 0xff000000 broadcast 127.255.255.255
inet6 ::1%1/64
tcp_sendspace 131072 tcp_recvspace 131072 rfc1323 1
>>> re.findall(r'^(\S+).*?[\s]+inet ([\d\.]+) netmask ([\w.]+) broadcast ([\d\.]+)', ifconfig_output, re.S | re.M)
[('en0:', '172.16.84.106', '0xffffc000', '172.16.127.255'), ('en1:', '172.17.8.4', '0xfffff800', '172.17.15.255'), ('lo0:', '127.0.0.1', '0xff000000', '127.255.255.255')]
