1 from os import system, popen, path as os_path, listdir
2 from re import compile as re_compile, search as re_search
4 from enigma import eConsoleAppContainer
5 from Components.Console import Console
6 from Components.PluginComponent import plugins
7 from Components.About import about
8 from Plugins.Plugin import PluginDescriptor
13 self.configuredInterfaces = []
14 self.configuredNetworkAdapters = []
18 self.ethtool_bin = "ethtool"
19 self.container = eConsoleAppContainer()
20 self.Console = Console()
21 self.LinkConsole = Console()
22 self.restartConsole = Console()
23 self.deactivateInterfaceConsole = Console()
24 self.activateInterfaceConsole = Console()
25 self.resetNetworkConsole = Console()
26 self.DnsConsole = Console()
27 self.PingConsole = Console()
28 self.config_ready = None
29 self.friendlyNames = {}
30 self.lan_interfaces = []
31 self.wlan_interfaces = []
32 self.remoteRootFS = None
35 def onRemoteRootFS(self):
36 if self.remoteRootFS == None:
37 fp = file('/proc/mounts', 'r')
38 mounts = fp.readlines()
40 self.remoteRootFS = False
42 parts = line.strip().split()
43 if parts[1] == '/' and parts[2] == 'nfs':
44 self.remoteRootFS = True
46 return self.remoteRootFS
48 def isBlacklisted(self, iface):
49 return iface in ('lo', 'wifi0', 'wmaster0')
51 def getInterfaces(self, callback = None):
52 self.configuredInterfaces = []
53 for device in self.getInstalledAdapters():
54 self.getAddrInet(device, callback)
57 def regExpMatch(self, pattern, string):
61 return pattern.search(string).group()
62 except AttributeError:
65 # helper function to convert ips from a sring to a list of ints
66 def convertIP(self, ip):
67 return [ int(n) for n in ip.split('.') ]
69 def getAddrInet(self, iface, callback):
71 self.Console = Console()
72 cmd = "ip -o addr show dev " + iface
73 self.Console.ePopen(cmd, self.IPaddrFinished, [iface,callback])
75 def IPaddrFinished(self, result, retval, extra_args):
76 (iface, callback ) = extra_args
77 data = { 'up': False, 'dhcp': False, 'preup' : False, 'predown' : False, 'dns-nameservers' : False }
78 globalIPpattern = re_compile("scope global")
79 ipRegexp = '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
80 netRegexp = '[0-9]{1,2}'
81 macRegexp = '[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}'
82 ipLinePattern = re_compile('inet ' + ipRegexp + '/')
83 ipPattern = re_compile(ipRegexp)
84 netmaskLinePattern = re_compile('/' + netRegexp)
85 netmaskPattern = re_compile(netRegexp)
86 bcastLinePattern = re_compile(' brd ' + ipRegexp)
87 upPattern = re_compile('UP')
88 macPattern = re_compile(macRegexp)
89 macLinePattern = re_compile('link/ether ' + macRegexp)
91 for line in result.splitlines():
92 split = line.strip().split(' ',2)
93 if (split[1][:-1] == iface):
94 up = self.regExpMatch(upPattern, split[2])
95 mac = self.regExpMatch(macPattern, self.regExpMatch(macLinePattern, split[2]))
99 self.configuredInterfaces.append(iface)
102 if (split[1] == iface):
103 if re_search(globalIPpattern, split[2]):
104 ip = self.regExpMatch(ipPattern, self.regExpMatch(ipLinePattern, split[2]))
105 netmask = self.calc_netmask(self.regExpMatch(netmaskPattern, self.regExpMatch(netmaskLinePattern, split[2])))
106 bcast = self.regExpMatch(ipPattern, self.regExpMatch(bcastLinePattern, split[2]))
108 data['ip'] = self.convertIP(ip)
109 if netmask is not None:
110 data['netmask'] = self.convertIP(netmask)
111 if bcast is not None:
112 data['bcast'] = self.convertIP(bcast)
114 if not data.has_key('ip'):
116 data['ip'] = [0, 0, 0, 0]
117 data['netmask'] = [0, 0, 0, 0]
118 data['gateway'] = [0, 0, 0, 0]
120 cmd = "route -n | grep " + iface
121 self.Console.ePopen(cmd,self.routeFinished, [iface, data, callback])
123 def routeFinished(self, result, retval, extra_args):
124 (iface, data, callback) = extra_args
125 ipRegexp = '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
126 ipPattern = re_compile(ipRegexp)
127 ipLinePattern = re_compile(ipRegexp)
129 for line in result.splitlines():
131 if line[0:7] == "0.0.0.0":
132 gateway = self.regExpMatch(ipPattern, line[16:31])
134 data['gateway'] = self.convertIP(gateway)
136 self.ifaces[iface] = data
137 self.loadNetworkConfig(iface,callback)
139 def writeNetworkConfig(self):
140 self.configuredInterfaces = []
141 fp = file('/etc/network/interfaces', 'w')
142 fp.write("# automatically generated by enigma 2\n# do NOT change manually!\n\n")
143 fp.write("auto lo\n")
144 fp.write("iface lo inet loopback\n\n")
145 for ifacename, iface in self.ifaces.items():
146 if iface['up'] == True:
147 fp.write("auto " + ifacename + "\n")
148 self.configuredInterfaces.append(ifacename)
149 if iface['dhcp'] == True:
150 fp.write("iface "+ ifacename +" inet dhcp\n")
151 if iface['dhcp'] == False:
152 fp.write("iface "+ ifacename +" inet static\n")
153 if iface.has_key('ip'):
154 print tuple(iface['ip'])
155 fp.write(" address %d.%d.%d.%d\n" % tuple(iface['ip']))
156 fp.write(" netmask %d.%d.%d.%d\n" % tuple(iface['netmask']))
157 if iface.has_key('gateway'):
158 fp.write(" gateway %d.%d.%d.%d\n" % tuple(iface['gateway']))
159 if iface.has_key("configStrings"):
160 fp.write(iface["configStrings"])
161 if iface["preup"] is not False and not iface.has_key("configStrings"):
162 fp.write(iface["preup"])
163 if iface["predown"] is not False and not iface.has_key("configStrings"):
164 fp.write(iface["predown"])
165 if iface["dns-nameservers"] is not False and len(iface["dns-nameservers"])>0:
166 fp.write("%s" % (iface["dns-nameservers"]))
169 self.configuredNetworkAdapters = self.configuredInterfaces
170 # self.writeNameserverConfig()
172 def writeNameserverConfig(self):
173 fp = file('/etc/resolv.conf', 'w')
174 for nameserver in self.nameservers:
175 fp.write("nameserver %d.%d.%d.%d\n" % tuple(nameserver))
178 def loadNetworkConfig(self,iface,callback = None):
180 # parse the interfaces-file
182 fp = file('/etc/network/interfaces', 'r')
183 interfaces = fp.readlines()
186 print "[Network.py] interfaces - opening failed"
191 split = i.strip().split(' ')
192 if (split[0] == "iface"):
195 if (len(split) == 4 and split[3] == "dhcp"):
196 ifaces[currif]["dhcp"] = True
198 ifaces[currif]["dhcp"] = False
199 if (currif == iface): #read information only for available interfaces
200 if (split[0] == "address"):
201 ifaces[currif]["address"] = map(int, split[1].split('.'))
202 if self.ifaces[currif].has_key("ip"):
203 if self.ifaces[currif]["ip"] != ifaces[currif]["address"] and ifaces[currif]["dhcp"] == False:
204 self.ifaces[currif]["ip"] = map(int, split[1].split('.'))
205 if (split[0] == "netmask"):
206 ifaces[currif]["netmask"] = map(int, split[1].split('.'))
207 if self.ifaces[currif].has_key("netmask"):
208 if self.ifaces[currif]["netmask"] != ifaces[currif]["netmask"] and ifaces[currif]["dhcp"] == False:
209 self.ifaces[currif]["netmask"] = map(int, split[1].split('.'))
210 if (split[0] == "gateway"):
211 ifaces[currif]["gateway"] = map(int, split[1].split('.'))
212 if self.ifaces[currif].has_key("gateway"):
213 if self.ifaces[currif]["gateway"] != ifaces[currif]["gateway"] and ifaces[currif]["dhcp"] == False:
214 self.ifaces[currif]["gateway"] = map(int, split[1].split('.'))
215 if (split[0] == "pre-up"):
216 if self.ifaces[currif].has_key("preup"):
217 self.ifaces[currif]["preup"] = i
218 if (split[0] in ("pre-down","post-down")):
219 if self.ifaces[currif].has_key("predown"):
220 self.ifaces[currif]["predown"] = i
221 if (split[0] == "dns-nameservers"):
222 if self.ifaces[currif].has_key("dns-nameservers"):
223 self.ifaces[currif]["dns-nameservers"] = i
225 for ifacename, iface in ifaces.items():
226 if self.ifaces.has_key(ifacename):
227 self.ifaces[ifacename]["dhcp"] = iface["dhcp"]
229 if len(self.Console.appContainers) == 0:
230 # save configured interfacelist
231 self.configuredNetworkAdapters = self.configuredInterfaces
233 self.loadNameserverConfig()
234 print "read configured interface:", ifaces
235 print "self.ifaces after loading:", self.ifaces
236 self.config_ready = True
238 if callback is not None:
241 def loadNameserverConfig(self):
242 ipRegexp = "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
243 nameserverPattern = re_compile("nameserver +" + ipRegexp)
244 ipPattern = re_compile(ipRegexp)
248 fp = file('/etc/resolv.conf', 'r')
249 resolv = fp.readlines()
251 self.nameservers = []
253 print "[Network.py] resolv.conf - opening failed"
256 if self.regExpMatch(nameserverPattern, line) is not None:
257 ip = self.regExpMatch(ipPattern, line)
259 self.nameservers.append(self.convertIP(ip))
261 print "nameservers:", self.nameservers
263 def getInstalledAdapters(self):
264 return [x for x in listdir('/sys/class/net') if not self.isBlacklisted(x)]
266 def getConfiguredAdapters(self):
267 return self.configuredNetworkAdapters
269 def getNumberOfAdapters(self):
270 return len(self.ifaces)
272 def getFriendlyAdapterName(self, x):
273 if x in self.friendlyNames.keys():
274 return self.friendlyNames.get(x, x)
275 self.friendlyNames[x] = self.getFriendlyAdapterNaming(x)
276 return self.friendlyNames.get(x, x) # when we have no friendly name, use adapter name
278 def getFriendlyAdapterNaming(self, iface):
280 if self.isWirelessInterface(iface):
281 if iface not in self.wlan_interfaces:
282 name = _("WLAN connection")
283 if len(self.wlan_interfaces):
284 name += " " + str(len(self.wlan_interfaces)+1)
285 self.wlan_interfaces.append(iface)
287 if iface not in self.lan_interfaces:
288 name = _("LAN connection")
289 if len(self.lan_interfaces):
290 name += " " + str(len(self.lan_interfaces)+1)
291 self.lan_interfaces.append(iface)
294 def getFriendlyAdapterDescription(self, iface):
295 if not self.isWirelessInterface(iface):
296 return _('Ethernet network interface')
298 moduledir = self.getWlanModuleDir(iface)
300 name = os_path.basename(os_path.realpath(moduledir))
301 if name in ('ath_pci','ath5k'):
303 elif name in ('rt73','rt73usb','rt3070sta'):
305 elif name == 'zd1211b':
307 elif name == 'r871x_usb_drv':
312 return name + ' ' + _('wireless network interface')
314 def getAdapterName(self, iface):
317 def getAdapterList(self):
318 return self.ifaces.keys()
320 def getAdapterAttribute(self, iface, attribute):
321 if self.ifaces.has_key(iface):
322 if self.ifaces[iface].has_key(attribute):
323 return self.ifaces[iface][attribute]
326 def setAdapterAttribute(self, iface, attribute, value):
327 print "setting for adapter", iface, "attribute", attribute, " to value", value
328 if self.ifaces.has_key(iface):
329 self.ifaces[iface][attribute] = value
331 def removeAdapterAttribute(self, iface, attribute):
332 if self.ifaces.has_key(iface):
333 if self.ifaces[iface].has_key(attribute):
334 del self.ifaces[iface][attribute]
336 def getNameserverList(self):
337 if len(self.nameservers) == 0:
338 return [[0, 0, 0, 0], [0, 0, 0, 0]]
340 return self.nameservers
342 def clearNameservers(self):
343 self.nameservers = []
345 def addNameserver(self, nameserver):
346 if nameserver not in self.nameservers:
347 self.nameservers.append(nameserver)
349 def removeNameserver(self, nameserver):
350 if nameserver in self.nameservers:
351 self.nameservers.remove(nameserver)
353 def changeNameserver(self, oldnameserver, newnameserver):
354 if oldnameserver in self.nameservers:
355 for i in range(len(self.nameservers)):
356 if self.nameservers[i] == oldnameserver:
357 self.nameservers[i] = newnameserver
359 def resetNetworkConfig(self, mode='lan', callback = None):
360 self.resetNetworkConsole = Console()
362 self.commands.append("/etc/init.d/avahi-daemon stop")
363 for iface in self.ifaces.keys():
364 if iface != 'eth0' or not self.onRemoteRootFS():
365 self.commands.append("ip addr flush dev " + iface)
366 self.commands.append("/etc/init.d/networking stop")
367 self.commands.append("killall -9 udhcpc")
368 self.commands.append("rm /var/run/udhcpc*")
369 self.resetNetworkConsole.eBatch(self.commands, self.resetNetworkFinishedCB, [mode, callback], debug=True)
371 def resetNetworkFinishedCB(self, extra_args):
372 (mode, callback) = extra_args
373 if len(self.resetNetworkConsole.appContainers) == 0:
374 self.writeDefaultNetworkConfig(mode, callback)
376 def writeDefaultNetworkConfig(self,mode='lan', callback = None):
377 fp = file('/etc/network/interfaces', 'w')
378 fp.write("# automatically generated by enigma 2\n# do NOT change manually!\n\n")
379 fp.write("auto lo\n")
380 fp.write("iface lo inet loopback\n\n")
382 fp.write("auto wlan0\n")
383 fp.write("iface wlan0 inet dhcp\n")
384 if mode == 'wlan-mpci':
385 fp.write("auto ath0\n")
386 fp.write("iface ath0 inet dhcp\n")
388 fp.write("auto eth0\n")
389 fp.write("iface eth0 inet dhcp\n")
393 self.resetNetworkConsole = Console()
396 self.commands.append("ifconfig eth0 down")
397 self.commands.append("ifconfig ath0 down")
398 self.commands.append("ifconfig wlan0 up")
399 if mode == 'wlan-mpci':
400 self.commands.append("ifconfig eth0 down")
401 self.commands.append("ifconfig wlan0 down")
402 self.commands.append("ifconfig ath0 up")
404 self.commands.append("ifconfig eth0 up")
405 self.commands.append("ifconfig wlan0 down")
406 self.commands.append("ifconfig ath0 down")
407 self.commands.append("/etc/init.d/avahi-daemon start")
408 self.resetNetworkConsole.eBatch(self.commands, self.resetNetworkFinished, [mode,callback], debug=True)
410 def resetNetworkFinished(self,extra_args):
411 (mode, callback) = extra_args
412 if len(self.resetNetworkConsole.appContainers) == 0:
413 if callback is not None:
416 def checkNetworkState(self,statecallback):
417 # www.dream-multimedia-tv.de, www.heise.de, www.google.de
418 self.NetworkState = 0
419 cmd1 = "ping -c 1 82.149.226.170"
420 cmd2 = "ping -c 1 193.99.144.85"
421 cmd3 = "ping -c 1 209.85.135.103"
422 self.PingConsole = Console()
423 self.PingConsole.ePopen(cmd1, self.checkNetworkStateFinished,statecallback)
424 self.PingConsole.ePopen(cmd2, self.checkNetworkStateFinished,statecallback)
425 self.PingConsole.ePopen(cmd3, self.checkNetworkStateFinished,statecallback)
427 def checkNetworkStateFinished(self, result, retval,extra_args):
428 (statecallback) = extra_args
429 if self.PingConsole is not None:
431 self.PingConsole = None
432 statecallback(self.NetworkState)
434 self.NetworkState += 1
435 if len(self.PingConsole.appContainers) == 0:
436 statecallback(self.NetworkState)
438 def restartNetwork(self,callback = None):
439 self.restartConsole = Console()
440 self.config_ready = False
443 self.commands.append("/etc/init.d/avahi-daemon stop")
444 for iface in self.ifaces.keys():
445 if iface != 'eth0' or not self.onRemoteRootFS():
446 self.commands.append("ifdown " + iface)
447 self.commands.append("ip addr flush dev " + iface)
448 self.commands.append("/etc/init.d/networking stop")
449 self.commands.append("killall -9 udhcpc")
450 self.commands.append("rm /var/run/udhcpc*")
451 self.commands.append("/etc/init.d/networking start")
452 self.commands.append("/etc/init.d/avahi-daemon start")
453 self.restartConsole.eBatch(self.commands, self.restartNetworkFinished, callback, debug=True)
455 def restartNetworkFinished(self,extra_args):
456 ( callback ) = extra_args
457 if callback is not None:
460 def getLinkState(self,iface,callback):
461 cmd = self.ethtool_bin + " " + iface
462 self.LinkConsole = Console()
463 self.LinkConsole.ePopen(cmd, self.getLinkStateFinished,callback)
465 def getLinkStateFinished(self, result, retval,extra_args):
466 (callback) = extra_args
468 if self.LinkConsole is not None:
469 if len(self.LinkConsole.appContainers) == 0:
472 def stopPingConsole(self):
473 if self.PingConsole is not None:
474 if len(self.PingConsole.appContainers):
475 for name in self.PingConsole.appContainers.keys():
476 self.PingConsole.kill(name)
478 def stopLinkStateConsole(self):
479 if self.LinkConsole is not None:
480 if len(self.LinkConsole.appContainers):
481 for name in self.LinkConsole.appContainers.keys():
482 self.LinkConsole.kill(name)
484 def stopDNSConsole(self):
485 if self.DnsConsole is not None:
486 if len(self.DnsConsole.appContainers):
487 for name in self.DnsConsole.appContainers.keys():
488 self.DnsConsole.kill(name)
490 def stopRestartConsole(self):
491 if self.restartConsole is not None:
492 if len(self.restartConsole.appContainers):
493 for name in self.restartConsole.appContainers.keys():
494 self.restartConsole.kill(name)
496 def stopGetInterfacesConsole(self):
497 if self.Console is not None:
498 if len(self.Console.appContainers):
499 for name in self.Console.appContainers.keys():
500 self.Console.kill(name)
502 def stopDeactivateInterfaceConsole(self):
503 if self.deactivateInterfaceConsole is not None:
504 self.deactivateInterfaceConsole.killAll()
505 self.deactivateInterfaceConsole = None
507 def stopActivateInterfaceConsole(self):
508 if self.activateInterfaceConsole is not None:
509 self.activateInterfaceConsole.killAll()
510 self.activateInterfaceConsole = None
512 def checkforInterface(self,iface):
513 if self.getAdapterAttribute(iface, 'up') is True:
516 ret=system("ifconfig " + iface + " up")
517 system("ifconfig " + iface + " down")
523 def checkDNSLookup(self,statecallback):
524 cmd1 = "nslookup www.dream-multimedia-tv.de"
525 cmd2 = "nslookup www.heise.de"
526 cmd3 = "nslookup www.google.de"
527 self.DnsConsole = Console()
528 self.DnsConsole.ePopen(cmd1, self.checkDNSLookupFinished,statecallback)
529 self.DnsConsole.ePopen(cmd2, self.checkDNSLookupFinished,statecallback)
530 self.DnsConsole.ePopen(cmd3, self.checkDNSLookupFinished,statecallback)
532 def checkDNSLookupFinished(self, result, retval,extra_args):
533 (statecallback) = extra_args
534 if self.DnsConsole is not None:
536 self.DnsConsole = None
537 statecallback(self.DnsState)
540 if len(self.DnsConsole.appContainers) == 0:
541 statecallback(self.DnsState)
543 def deactivateInterface(self,ifaces,callback = None):
544 self.config_ready = False
547 def buildCommands(iface):
548 commands.append("ifdown " + iface)
549 commands.append("ip addr flush dev " + iface)
550 #wpa_supplicant sometimes doesn't quit properly on SIGTERM
551 if os_path.exists('/var/run/wpa_supplicant/'+ iface):
552 commands.append("wpa_cli -i" + iface + " terminate")
554 if not self.deactivateInterfaceConsole:
555 self.deactivateInterfaceConsole = Console()
557 if isinstance(ifaces, (list, tuple)):
559 if iface != 'eth0' or not self.onRemoteRootFS():
562 if ifaces == 'eth0' and self.onRemoteRootFS():
563 if callback is not None:
566 buildCommands(ifaces)
567 self.deactivateInterfaceConsole.eBatch(commands, self.deactivateInterfaceFinished, [ifaces,callback], debug=True)
569 def deactivateInterfaceFinished(self,extra_args):
570 (ifaces, callback) = extra_args
571 def checkCommandResult(iface):
572 if self.deactivateInterfaceConsole and self.deactivateInterfaceConsole.appResults.has_key("ifdown " + iface):
573 result = str(self.deactivateInterfaceConsole.appResults.get("ifdown " + iface)).strip("\n")
574 if result == "ifdown: interface " + iface + " not configured":
578 #ifdown sometimes can't get the interface down.
579 if isinstance(ifaces, (list, tuple)):
581 if checkCommandResult(iface) is False:
582 Console().ePopen(("ifconfig " + iface + " down" ))
584 if checkCommandResult(ifaces) is False:
585 Console().ePopen(("ifconfig " + ifaces + " down" ))
587 if self.deactivateInterfaceConsole:
588 if len(self.deactivateInterfaceConsole.appContainers) == 0:
589 if callback is not None:
592 def activateInterface(self,iface,callback = None):
593 if self.config_ready:
594 self.config_ready = False
596 if iface == 'eth0' and self.onRemoteRootFS():
597 if callback is not None:
600 if not self.activateInterfaceConsole:
601 self.activateInterfaceConsole = Console()
603 commands.append("ifup " + iface)
604 self.activateInterfaceConsole.eBatch(commands, self.activateInterfaceFinished, callback, debug=True)
606 def activateInterfaceFinished(self,extra_args):
607 callback = extra_args
608 if self.activateInterfaceConsole:
609 if len(self.activateInterfaceConsole.appContainers) == 0:
610 if callback is not None:
613 def sysfsPath(self, iface):
614 return '/sys/class/net/' + iface
616 def isWirelessInterface(self, iface):
617 if iface in self.wlan_interfaces:
620 if os_path.isdir(self.sysfsPath(iface) + '/wireless'):
623 # r871x_usb_drv on kernel 2.6.12 is not identifiable over /sys/class/net/'ifacename'/wireless so look also inside /proc/net/wireless
624 device = re_compile('[a-z]{2,}[0-9]*:')
626 fp = open('/proc/net/wireless', 'r')
629 ifnames.append(device.search(line).group()[:-1])
630 except AttributeError:
637 def getWlanModuleDir(self, iface = None):
638 devicedir = self.sysfsPath(iface) + '/device'
639 moduledir = devicedir + '/driver/module'
640 if os_path.isdir(moduledir):
643 # identification is not possible over default moduledir
644 for x in listdir(devicedir):
645 # rt3070 on kernel 2.6.18 registers wireless devices as usb_device (e.g. 1-1.3:1.0) and identification is only possible over /sys/class/net/'ifacename'/device/1-xxx
646 if x.startswith("1-"):
647 moduledir = devicedir + '/' + x + '/driver/module'
648 if os_path.isdir(moduledir):
650 # rt73, zd1211b, r871x_usb_drv on kernel 2.6.12 can be identified over /sys/class/net/'ifacename'/device/driver, so look also here
651 moduledir = devicedir + '/driver'
652 if os_path.isdir(moduledir):
657 def detectWlanModule(self, iface = None):
658 if not self.isWirelessInterface(iface):
661 devicedir = self.sysfsPath(iface) + '/device'
662 if os_path.isdir(devicedir + '/ieee80211'):
665 moduledir = self.getWlanModuleDir(iface)
667 module = os_path.basename(os_path.realpath(moduledir))
668 if module in ('ath_pci','ath5k'):
670 if module in ('rt73','rt73'):
672 if module == 'zd1211b':
676 def calc_netmask(self,nmask):
677 from struct import pack, unpack
678 from socket import inet_ntoa, inet_aton
681 cidr_range = range(0, 32)
683 if cidr not in cidr_range:
684 print 'cidr invalid: %d' % cidr
687 nm = ((1L<<cidr)-1)<<(32-cidr)
688 netmask = str(inet_ntoa(pack('>L', nm)))
691 def msgPlugins(self):
692 if self.config_ready is not None:
693 for p in plugins.getPlugins(PluginDescriptor.WHERE_NETWORKCONFIG_READ):
694 p(reason=self.config_ready)
696 def getInterfacesNameserverList(self, iface):
698 nameservers = self.getAdapterAttribute(iface, "dns-nameservers")
700 ipRegexp = '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
701 ipPattern = re_compile(ipRegexp)
702 for x in nameservers.split()[1:]:
703 ip = self.regExpMatch(ipPattern, x)
705 result.append( [ int(n) for n in ip.split('.') ] )