def validate(cls, value): ip_utils = IpAddrUtils() if ip_utils.is_valid_ip(value) is False: raise ValueError( 'Invalid IP address format: expected IPv4 or IPv6 address. provided: {}' .format(value)) return value
def __init__(self, data: bytes) -> None: if len(data) > 12: data = data[:12] version, opcode, result, sec_since_epoch, self.integer_ip = \ struct.unpack(EXTERNAL_ADDRESS_RESPONSE_FORMAT, data) super(ExternalAddressResponse, self).__init__(version, opcode, result, sec_since_epoch) self.ip = IpAddrUtils().int_to_ip(self.integer_ip)
def test_natpmp_external_address_response_parsed_as_expected(self): mock_version = 1 mock_opcode = 128 mock_result = 0 mock_sec_since_epoch = 1800 mock_ip = '1.1.1.1' mock_ip_int = IpAddrUtils().ip_to_int(mock_ip) natpmp_response = ExternalAddressResponseBuilder( version=mock_version, opcode=mock_opcode, result=mock_result, sec_since_epoch=mock_sec_since_epoch, integer_ip=mock_ip_int) natpmp_packet = Natpmp(natpmp_response.to_bytes()) natpmp_data = self.natpmp_packet_parser.extract_data(natpmp_packet) self.assertEqual(mock_version, natpmp_data.natpmp_version) self.assertEqual(mock_opcode, natpmp_data.natpmp_opcode) self.assertEqual(mock_result, natpmp_data.natpmp_result) self.assertEqual(mock_sec_since_epoch, natpmp_data.natpmp_sssoe) self.assertEqual(mock_ip_int, natpmp_data.natpmp_external_ip)
def test_ipv6_regex_validation(self): ip_utils = IpAddrUtils() for ip_addr in IPv6_ADDRESSES: self.assertTrue(ip_utils.is_valid_ip(ip_addr))
def __init__(self, config: ConfigurationData): self.config = config self.ip_utils = IpAddrUtils()
def __init__(self, *args, **kwargs): super(BasePacketParserTests, self).__init__(*args, **kwargs) self.ip_utils = IpAddrUtils() self.mac_utils = MacAddressUtils() self.config = CONFIGURATION_OBJ self.static_data = StaticData()
def __init__(self, config: ConfigurationData, static_data: StaticData = None): self.mac_utils = MacAddressUtils() self.ip_utils = IpAddrUtils() self.ether_type_data = StaticData.load_ether_types_data() self.config = config self.static_data = static_data or StaticData()
def __init__(self, config: ConfigurationData, static_data: StaticData = None): self.config = config self.ip_utils = IpAddrUtils() self.static_data = static_data or StaticData()