I'm checking the replies of my previous code on Create network interfaces list using Python. E A Faisal suggestion to use
/proc/net/dev is somehow seems interesting to me. Now, let's do some python code for fun before going out to lunch.
Here is my code to get the same result as my previous python code to list the network interfaces:
# read the file /proc/net/dev
f = open('/proc/net/dev','r')
# put the content to list
ifacelist = f.read().split('\n')
# close the file
# remove 2 lines header
# loop to check each line
for line in ifacelist:
ifacedata = line.replace(' ','').split(':')
# check the data have 2 elements
if len(ifacedata) == 2:
# check the interface is up (Transmit/Receive data)
if int(ifacedata) > 0:
# print the interface
Seems like it is working on my ubuntu linux (in the office ). I believe it should possibly work on other linux without any issue with that SIOCGIFCONF and ioctl. And the code is even simpler.
That's all for now... I'm going out for lunch. Happy python coding!