コード例 #1
0
 def gateway(self, val):
     if val is not None:
         if not utils.is_ip(val):
             raise exceptions.EthercutException(
                 "Invalid gateway address specified as argument -g \"%s\"" %
                 val)
     self._gateway = val
コード例 #2
0
 def __setattr__(self, attr, val):
     if attr == "mac" and val:
         val = utils.normalize(val)
         self.vendor = utils.vendor_lookup(val)
     elif attr == "ip" and val:
         if not utils.is_ip(val) and not utils.is_ip6(val):
             raise ValueError("Invalid IP address '%s'" % val)
     return object.__setattr__(self, attr, val)
コード例 #3
0
 def __contains__(self, item):
     """
     Returns true if item belongs to this network.
     """
     if not utils.is_ip(item):
         return False
     # Use our netmask to check if the IP could belong to our network
     other_net = utils.aton(item) & self.mask32
     return self.net32 == other_net
コード例 #4
0
    def __setattr__(self, attr, val):
        if attr in ["network", "netmask"]:
            if not utils.is_ip(
                    val):  # Check that we introduced a valid address
                raise ValueError(
                    "%s needs to be a valid IP format address (x.x.x.x)" %
                    attr)

        object.__setattr__(self, attr, val)
コード例 #5
0
 def __contains__(self, other):
     """
     Checks if an IP or MAC address is contained in this specifications
     """
     if self.all:
         return True
     if utils.is_ip(other):
         if self.ip is None or other in self.ip:
             return True
     elif utils.is_mac(other):
         if self.mac is None or other in self.mac:
             return True
     return False
コード例 #6
0
 def targets(self, val):
     targets = []
     if val is not None:
         for t in val.split(","):
             try:
                 ip, mac, port = t.split("/")
                 port = utils.expand_port(port)
                 if ip and not utils.is_ip(ip):
                     raise exceptions.EthercutException("Invalid IP address")
                 if mac and not utils.is_mac(mac):
                     raise exceptions.EthercutException("Invalid MAC address")
                 targets.append((ip, mac, port))
             except ValueError:
                 raise exceptions.EthercutException("Unexpected number of \"/\" (//)")
             except exceptions.EthercutException as e:
                 raise exceptions.EthercutException("%s in -T %s" %(str(e), t))
     self._targets = targets