+ def loadNetworkConfig(self):
+ self.loadNameserverConfig()
+
+ interfaces = []
+ # parse the interfaces-file
+ try:
+ fp = file('/etc/network/interfaces', 'r')
+ interfaces = fp.readlines()
+ fp.close()
+ except:
+ print "[Network.py] interfaces - opening failed"
+
+ ifaces = {}
+ currif = ""
+ for i in interfaces:
+ split = i.strip().split(' ')
+ if (split[0] == "iface"):
+ currif = split[1]
+ ifaces[currif] = {}
+ if (len(split) == 4 and split[3] == "dhcp"):
+ ifaces[currif]["dhcp"] = True
+ else:
+ ifaces[currif]["dhcp"] = False
+ if (currif != ""):
+ if (split[0] == "address"):
+ ifaces[currif]["address"] = map(int, split[1].split('.'))
+ if (split[0] == "netmask"):
+ ifaces[currif]["netmask"] = map(int, split[1].split('.'))
+ if (split[0] == "gateway"):
+ ifaces[currif]["gateway"] = map(int, split[1].split('.'))
+
+ print "read interfaces:", ifaces
+ for ifacename, iface in ifaces.items():
+ if self.ifaces.has_key(ifacename):
+ self.ifaces[ifacename]["dhcp"] = iface["dhcp"]
+
+ print "self.ifaces after loading:", self.ifaces
+
+ 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)
+
+ resolv = []
+ try:
+ fp = file('/etc/resolv.conf', 'r')
+ resolv = fp.readlines()
+ fp.close()
+ self.nameservers = []
+ except:
+ print "[Network.py] resolv.conf - opening failed"
+
+ for line in resolv:
+ if self.regExpMatch(nameserverPattern, line) is not None:
+ ip = self.regExpMatch(ipPattern, line)
+ if ip is not None:
+ self.nameservers.append(self.convertIP(ip))
+
+ print "nameservers:", self.nameservers