diff options
Diffstat (limited to 'abs/core/LinHES-config/mv_network.py')
-rwxr-xr-x | abs/core/LinHES-config/mv_network.py | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/abs/core/LinHES-config/mv_network.py b/abs/core/LinHES-config/mv_network.py index aab1345..d0fa16c 100755 --- a/abs/core/LinHES-config/mv_network.py +++ b/abs/core/LinHES-config/mv_network.py @@ -18,17 +18,32 @@ def setup_MYTH_DHCP(systemconfig): return defaultdhcp def all_interfaces(): - max_possible = 128 # arbitrary. raise if needed. - bytes = max_possible * 32 - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - names = array.array('B', '\0' * bytes) - outbytes = struct.unpack('iL', fcntl.ioctl( - s.fileno(), - 0x8912, # SIOCGIFCONF - struct.pack('iL', bytes, names.buffer_info()[0]) - ))[0] - namestr = names.tostring() - return [namestr[i:i+32].split('\0', 1)[0] for i in range(0, outbytes, 32)] + # read the file /proc/net/dev + ifacelist=[] + returnlist=[] + try: + f = open('/proc/net/dev','r') + # put the content to list + ifacelist = f.read().split('\n') + # close the file + f.close() + # remove 2 lines header + ifacelist.pop(0) + ifacelist.pop(0) + except: + logging.critical(" *Problem reading /proc/net/dev") + + # 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[1]) > 0: + #print ifacedata[0] + returnlist.append(ifacedata[0]) + + return returnlist def get_ip(ifname): logging.debug(" Finding ip address for %s", ifname) @@ -43,12 +58,16 @@ def get_ip(ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - return socket.inet_ntoa(fcntl.ioctl( + + ip = socket.inet_ntoa(fcntl.ioctl( s.fileno(), 0x8915, # SIOCGIFADDR struct.pack('256s', ifname[:15]) )[20:24]) + logging.debug(" get_ip ip address is %s", ip) + return ip + def get_default_route(iface): rcroute = "127.0.0.1" f = open ('/proc/net/route', 'r') |