X-Git-Url: http://code.vuplus.com/gitweb/?p=vuplus_dvbapp;a=blobdiff_plain;f=lib%2Fpython%2FComponents%2FAbout.py;h=4b6140696ecc26a9d817a774dfdb6f23f1e2850c;hp=6b322c9d560b0ab6b142dd83bf561841c263cb88;hb=0fee8bdaa26f854460b63475c91f1f2cf762594b;hpb=9ec5fc545cfff7addbfd5b50ee9d6d60ab419e0d diff --git a/lib/python/Components/About.py b/lib/python/Components/About.py index 6b322c9..4b61406 100755 --- a/lib/python/Components/About.py +++ b/lib/python/Components/About.py @@ -54,4 +54,62 @@ class About: return "unknown" + def getIfaces(self): + import socket, fcntl, struct, array, sys + SIOCGIFCONF = 0x8912 # sockios.h + is_64bits = sys.maxsize > 2**32 + struct_size = 40 if is_64bits else 32 + max_possible = 8 # initial value + sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + while True: + # ifconf structure: + # struct ifconf { + # int ifc_len; /* size of buffer */ + # union { + # char *ifc_buf; /* buffer address */ + # struct ifreq *ifc_req; /* array of structures */ + # }; + # }; + # + # struct ifreq: + # #define IFNAMSIZ 16 + # struct ifreq { + # char ifr_name[IFNAMSIZ]; /* Interface name */ + # union { + # struct sockaddr ifr_addr; + # ..... + # }; + # }; + + # Initialize ifc_buf + bytes = max_possible * struct_size + names = array.array('B') + for i in range(0, bytes): + names.append(0) + + input_buffer = struct.pack( 'iL', bytes, names.buffer_info()[0] ) + output_buffer = fcntl.ioctl( sock.fileno(), SIOCGIFCONF, input_buffer ) + output_size = struct.unpack('iL', output_buffer)[0] + + if output_size == bytes: + max_possible *= 2 + else: + break + + namestr = names.tostring() + ifaces = [] + for i in range(0, output_size, struct_size): + iface_name = namestr[i:i+16].split('\0', 1)[0] + iface_addr = socket.inet_ntoa(namestr[i+20:i+24]) + if iface_name != 'lo': + ifaces.append((iface_name, iface_addr)) + + return ifaces + + def getNetworkInfo(self): + data = "" + for x in self.getIfaces(): + data += "%s : %s\n" % (x[0], x[1]) + return data or "\tnot connected" + about = About()