コード例 #1
0
def udp_send(test_params, data):
    """Send data using UDP protocol."""
    dst_ip = IPY_IP(test_params.dst_endpoint.ip_addr)
    if dst_ip.version() == 4:
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    elif dst_ip.version() == 6:
        sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
    sock.settimeout(test_params.timeout_sec)

    request_size = len(data)
    # response_size = 0
    print_verbose(
        test_params,
        "src_ip: {} src_port: {} nr_retries: {}".format(
            test_params.src_endpoint.ip_addr,
            test_params.src_endpoint.port,
            test_params.nr_retries,
        ),
    )

    sock.sendto(
        data,
        (test_params.dst_endpoint.ip_addr, test_params.dst_endpoint.port))

    try:
        in_data, server_addr = sock.recvfrom(INPUT_BUFFER_SIZE)
    except socket.timeout:
        print_verbose(test_params, "Timeout")
        print_verbose(test_params, "Request size = {}".format(request_size))
        return None

    response_size = len(in_data)
    print_verbose(
        test_params,
        "Received packet size {} from {}".format(len(in_data), server_addr))

    try:
        response = DTLSRecord(in_data)
    except struct.error:
        print_verbose(test_params, "Parsing of DTLS message failed!")
        print_verbose(test_params, "Request size = {}".format(request_size))
        print_verbose(test_params, "Response size = {}".format(response_size))
        return in_data

    print_verbose(test_params,
                  "Received packet DTLS type {}".format(response.content_type))
    show_verbose(test_params, response)
    return response
コード例 #2
0
ファイル: cotopaxi_tester.py プロジェクト: xsec-team/cotopaxi
def prepare_ips(ips_input):
    """Parses IPs description taken from command line into sorted list of unique ip addresses.

        Args:
            ips_input (str): IP addresses description in format: '1.1.1.1,2.2.2.2/31'.

        Returns:
            list: Sorted list of unique IP addresses
                e.g.: ['1.1.1.1', '2.2.2.2', '2.2.2.3'] for the above example.
    """
    try:
        test_ips = [
            ip_addr for address_desc in ips_input.split(",")
            for ip_addr in IPY_IP(address_desc, make_net=1)
        ]
    except ValueError as value_error:
        exit("Cannot parse IP address: {}".format(value_error))
    test_ips = sorted(set(map(str, test_ips)))
    return test_ips
コード例 #3
0
ファイル: cotopaxi_tester.py プロジェクト: xsec-team/cotopaxi
 def set_ip_version(self):
     """Function identifies IP version of the protocol"""
     ip_addr = IPY_IP(self.dst_endpoint.ip_addr)
     if ip_addr.version() == 6:
         self.ip_version = 6
コード例 #4
0
ファイル: cotopaxi_tester.py プロジェクト: add1ct3d/cotopaxi
 def set_ip_version(self):
     """Set IP version of the protocol."""
     ip_addr = IPY_IP(self.dst_endpoint.ip_addr)
     if ip_addr.version() == 6:
         self.ip_version = 6