From 220e0f52f066ee30b7617db3ca4ea09f77dddd3d Mon Sep 17 00:00:00 2001 From: Dmitriy Gafurov Date: Fri, 23 Feb 2018 17:51:52 +0200 Subject: [PATCH] deal with ip-address in CIDR format --- debinterface/interfacesReader.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/debinterface/interfacesReader.py b/debinterface/interfacesReader.py index 755f057..b655657 100644 --- a/debinterface/interfacesReader.py +++ b/debinterface/interfacesReader.py @@ -85,7 +85,23 @@ def _parse_details(self, line): sline = [x.strip() for x in line.split()] if sline[0] == 'address': - self._adapters[self._context].setAddress(sline[1]) + ip_mask = sline[1].split('/') + if len(ip_mask) == 1: + self._adapters[self._context].setAddress(sline[1]) + else: + self._adapters[self._context].setAddress(ip_mask[0]) + + cidr = int(ip_mask[1]) + mask = (0xffffffff >> (32 - cidr)) << (32 - cidr) + netmask = str((0xff000000 & mask) >> 24) + '.' + \ + str((0x00ff0000 & mask) >> 16) + '.' + \ + str((0x0000ff00 & mask) >> 8) + '.' + \ + str((0x000000ff & mask)) + + self._adapters[self._context].setNetmask(netmask) + sline[0] = 'netmask' + sline[1] = netmask + elif sline[0] == 'netmask': self._adapters[self._context].setNetmask(sline[1]) elif sline[0] == 'gateway':