-import os
-import re
+from os import system, popen, path as os_path, listdir
+from re import compile as re_compile
from socket import *
-from enigma import eTimer, eConsoleAppContainer
+from enigma import eConsoleAppContainer
class Network:
def __init__(self):
self.container = eConsoleAppContainer()
def getInterfaces(self):
- devicesPattern = re.compile('[a-z]+[0-9]+')
+ devicesPattern = re_compile('[a-z]+[0-9]+')
fp = file('/proc/net/dev', 'r')
result = fp.readlines()
for line in result:
try:
device = devicesPattern.search(line).group()
+ if device == 'wifi0':
+ continue
self.ifaces[device] = self.getDataForInterface(device)
# Show only UP Interfaces in E2
- if self.getAdapterAttribute(device, 'up') is False:
- del self.ifaces[device]
+ #if self.getAdapterAttribute(device, 'up') is False:
+ # del self.ifaces[device]
except AttributeError:
pass
def getDataForInterface(self, iface):
#ipRegexp = '[0-9]{1,2,3}\.[0-9]{1,2,3}\.[0-9]{1,2,3}\.[0-9]{1,2,3}'
ipRegexp = '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
- ipLinePattern = re.compile('inet addr:' + ipRegexp)
- netmaskLinePattern = re.compile('Mask:' + ipRegexp)
- bcastLinePattern = re.compile('Bcast:' + ipRegexp)
- ipPattern = re.compile(ipRegexp)
- upPattern = re.compile('UP ')
- macPattern = re.compile('[0-9]{2}\:[0-9]{2}\:[0-9]{2}\:[0-9]{2}\:[0-9]{2}\:[0-9]{2}')
-
- fp = os.popen("ifconfig " + iface)
+ ipLinePattern = re_compile('inet addr:' + ipRegexp)
+ netmaskLinePattern = re_compile('Mask:' + ipRegexp)
+ bcastLinePattern = re_compile('Bcast:' + ipRegexp)
+ ipPattern = re_compile(ipRegexp)
+ upPattern = re_compile('UP ')
+ macPattern = re_compile('[0-9]{2}\:[0-9]{2}\:[0-9]{2}\:[0-9]{2}\:[0-9]{2}\:[0-9]{2}')
+
+ fp = popen("ifconfig " + iface)
result = fp.readlines()
fp.close()
data = { 'up': False, 'dhcp': False }
data['ip'] = [192, 168, 1, 2]
data['netmask'] = [255, 255, 255, 0]
data['gateway'] = [192, 168, 1, 1]
-
- fp = os.popen("route -n | grep " + iface)
+
+ fp = popen("route -n | grep " + iface)
result = fp.readlines()
fp.close()
for line in result:
fp.write("# automatically generated by enigma 2\n# do NOT change manually!\n\n")
fp.write("auto lo\n")
fp.write("iface lo inet loopback\n\n")
-
for ifacename, iface in self.ifaces.items():
if iface['up'] == True:
fp.write("auto " + ifacename + "\n")
- if iface['dhcp'] == True:
- fp.write("iface "+ ifacename +" inet dhcp\n")
- else:
- fp.write("iface "+ ifacename +" inet static\n")
- if iface.has_key('ip'):
- print tuple(iface['ip'])
- fp.write(" address %d.%d.%d.%d\n" % tuple(iface['ip']))
- fp.write(" netmask %d.%d.%d.%d\n" % tuple(iface['netmask']))
- if iface.has_key('gateway'):
- fp.write(" gateway %d.%d.%d.%d\n" % tuple(iface['gateway']))
-
- if iface.has_key("configStrings"):
- fp.write("\n" + iface["configStrings"] + "\n")
- fp.write("\n")
+ if iface['dhcp'] == True:
+ fp.write("iface "+ ifacename +" inet dhcp\n")
+ if iface['dhcp'] == False:
+ fp.write("iface "+ ifacename +" inet static\n")
+ if iface.has_key('ip'):
+ print tuple(iface['ip'])
+ fp.write(" address %d.%d.%d.%d\n" % tuple(iface['ip']))
+ fp.write(" netmask %d.%d.%d.%d\n" % tuple(iface['netmask']))
+ if iface.has_key('gateway'):
+ fp.write(" gateway %d.%d.%d.%d\n" % tuple(iface['gateway']))
+ if iface.has_key("configStrings"):
+ fp.write("\n" + iface["configStrings"] + "\n")
+ fp.write("\n")
fp.close()
self.writeNameserverConfig()
def loadNameserverConfig(self):
ipRegexp = "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
- nameserverPattern = re.compile("nameserver +" + ipRegexp)
- ipPattern = re.compile(ipRegexp)
+ nameserverPattern = re_compile("nameserver +" + ipRegexp)
+ ipPattern = re_compile(ipRegexp)
resolv = []
try:
def deactivateNetworkConfig(self):
for iface in self.ifaces.keys():
- os.system("ip addr flush " + iface)
- os.system("/etc/init.d/networking stop")
- os.system("killall -9 udhcpc")
- os.system("rm /var/run/udhcpc*")
+ system("ip addr flush " + iface)
+ system("/etc/init.d/networking stop")
+ system("killall -9 udhcpc")
+ system("rm /var/run/udhcpc*")
def activateNetworkConfig(self):
- os.system("/etc/init.d/networking start")
+ system("/etc/init.d/networking start")
self.getInterfaces()
def getNumberOfAdapters(self):
# maybe this needs to be replaced by an external list.
friendlyNames = {
"eth0": _("Integrated Ethernet"),
- "wlan0": _("Wireless")
+ "wlan0": _("Wireless"),
+ "ath0": _("Integrated Wireless")
}
return friendlyNames.get(x, x) # when we have no friendly name, use adapter name
if mode == 'wlan':
fp.write("auto wlan0\n")
fp.write("iface wlan0 inet dhcp\n")
- else:
+ if mode == 'wlan-mpci':
+ fp.write("auto ath0\n")
+ fp.write("iface ath0 inet dhcp\n")
+ if mode == 'lan':
fp.write("auto eth0\n")
fp.write("iface eth0 inet dhcp\n")
fp.write("\n")
self.deactivateNetworkConfig()
self.writeDefaultNetworkConfig(mode)
if mode == 'wlan':
- os.system("ifconfig eth0 down")
- os.system("ifconfig wlan0 up")
- else:
- os.system("ifconfig eth0 up")
- os.system("ifconfig wlan0 down")
+ system("ifconfig eth0 down")
+ system("ifconfig ath0 down")
+ system("ifconfig wlan0 up")
+ if mode == 'wlan-mpci':
+ system("ifconfig eth0 down")
+ system("ifconfig wlan0 down")
+ system("ifconfig ath0 up")
+ if mode == 'lan':
+ system("ifconfig eth0 up")
+ system("ifconfig wlan0 down")
+ system("ifconfig ath0 down")
+ self.getInterfaces()
def checkNetworkState(self):
- ok_counter = 0
- ret1=os.system("ping -c 1 www.dream-multimedia-tv.de")
- if ret1 != 0:
- ok_counter = ok_counter + 1
- ret2=os.system("ping -c 1 www.heise.de")
- if ret2 != 0:
- ok_counter = ok_counter + 1
- ret3=os.system("ping -c 1 www.google.de")
- if ret2 != 0:
- ok_counter = ok_counter + 1
- if ok_counter <= 2:
- return True
- else:
- return False
+ # www.dream-multimedia-tv.de, www.heise.de, www.google.de
+ return system("ping -c 1 82.149.226.170") == 0 or \
+ system("ping -c 1 193.99.144.85") == 0 or \
+ system("ping -c 1 209.85.135.103") == 0
def restartNetwork(self):
iNetwork.deactivateNetworkConfig()
self.container.dataAvail.get().remove(self.dataAvail)
def checkforInterface(self,iface):
- ret=os.system("ifconfig " + iface + " up")
- if ret == 0:
+ if self.getAdapterAttribute(iface, 'up') is True:
return True
else:
- return False
+ ret=system("ifconfig " + iface + " up")
+ system("ifconfig " + iface + " down")
+ if ret == 0:
+ return True
+ else:
+ return False
def checkDNSLookup(self):
- ok_counter = 0
- ret1=os.system("nslookup www.dream-multimedia-tv.de")
- if ret1 != 0:
- ok_counter = ok_counter + 1
- ret2=os.system("nslookup www.heise.de")
- if ret2 != 0:
- ok_counter = ok_counter + 1
- ret3=os.system("nslookup www.google.de")
- if ret2 != 0:
- ok_counter = ok_counter + 1
- if ok_counter <= 2:
- return True
- else:
- return False
-
+ return system("nslookup www.dream-multimedia-tv.de") == 0 or \
+ system("nslookup www.heise.de") == 0 or \
+ system("nslookup www.google.de")
+
+ def deactivateInterface(self,iface):
+ system("ifconfig " + iface + " down")
+
+ def detectWlanModule(self):
+ self.wlanmodule = None
+ rt73_dir = "/sys/bus/usb/drivers/rt73/"
+ zd1211b_dir = "/sys/bus/usb/drivers/zd1211b/"
+ madwifi_dir = "/sys/bus/pci/drivers/ath_pci/"
+ if os_path.exists(madwifi_dir):
+ files = listdir(madwifi_dir)
+ if len(files) >= 1:
+ self.wlanmodule = 'madwifi'
+ elif os_path.exists(rt73_dir):
+ files = listdir(rt73_dir)
+ if len(files) >= 1:
+ self.wlanmodule = 'ralink'
+ elif os_path.exists(zd1211b_dir):
+ files = listdir(zd1211b_dir)
+ if len(files) != 0:
+ self.wlanmodule = 'zydas'
+ return self.wlanmodule
+
+
iNetwork = Network()
def InitNetwork():