def get_os_net_ip(self): """все ip компьютера, разделитель запятая""" IPs = [] netInterfaces=cl_utils.getdirlist("/sys/class/net/") for i in netInterfaces: res = self._runos("/sbin/ifconfig %s"%i) if not res: break for line in res: searchIP = re.search('addr:([0-9\.]+).+Bcast:', line) if searchIP: # ip адрес ip = searchIP.groups()[0] IPs.append(ip) return ",".join(IPs)
def get_os_net_allow(self): """Разрешенные сети разделитель запятая""" def getNet(ip, mask): """По ip и маске получаем сеть""" octetsMult = (0x1, 0x100, 0x10000, 0x1000000) octetsIp = map(lambda x: int(x), ip.split(".")) octetsMask = map(lambda x: int(x), mask.split(".")) ipNumb = 0 for i in octetsMult: ipNumb += octetsIp.pop()*i maskNumb = 0 for i in octetsMult: maskNumb += octetsMask.pop()*i startIpNumber = maskNumb&ipNumb x = startIpNumber nMask = lambda y: len(filter(lambda x: y >> x &1 ,range(32))) return "%s.%s.%s.%s/%s"\ %(x>>24, x>>16&255, x>>8&255, x&255, nMask(maskNumb)) networks=[] netInterfaces=cl_utils.getdirlist("/sys/class/net/") flagError = False for i in netInterfaces: res = self._runos("/sbin/ifconfig %s"%i) if not res: flagError = True break for j in res: s_ip=re.search('addr:([0-9\.]+).+Bcast:.+Mask:([0-9\.]+)' ,j) if s_ip: ip, mask = s_ip.groups() networks.append(getNet(ip, mask)) if flagError: return "" return ",".join(networks)