Traceroute/Traceroute.py
def do_three_trace(dest_addr, ttl, sequence, time_out):
    """Create ICMP socket, send it and receive IP address of the current node.

    After extracting the current node IP address from receiveOneTrace function,
    we need to close the socket in order to cut the connection.

    Args:
        :param dest_addr: the IP address of the current node.
        :param ttl: Time To Live value.
        :param sequence: the nth times of the current node latency measurement.
        :param time_out: configurable timeout, set using an optional argument.

    Returns:
        :return: the IP address of the current node or a string ("Request timeout").
    """
    port_id = os.getpid()
    record_addr =""
    record = False
    for i in range(TIMES):
        # 1 is socket module constant associated with protocol ICMP.
        client_socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, 1)  # icmp.
        client_socket.setsockopt(socket.IPPROTO_IP, socket.IP_TTL, struct.pack('I', ttl))  # stop after ttl = 0
        client_socket.setsockopt(socket.SOL_SOCKET, socket.SO_RCVTIMEO, time_out)
        # 2. Call send_one_trace function.
        send_time = send_one_trace(client_socket, dest_addr, port_id, sequence)
        # 3. Call receive_one_trace function.
        route_addr = receive_one_trace(client_socket, send_time, time_out)
        if route_addr != "Request timeout" :
            record = True
            record_addr = route_addr
        client_socket.close()
    # During [TIMES] times measurements, once we get real IP address then record it.
    # Else, return "Request timeout".
    if record is True:
        return record_addr
    else:
        return route_addr
Create ICMP socket, send it and receive IP address of the current node.

    After extracting the current node IP address from receiveOneTrace function,
    we need to close the socket in order to cut the connection.

    Args:
        :param dest_addr: the IP address of the current node.
        :param ttl: Time To Live value.
        :param sequence: the nth times of the current node latency measurement.
        :param time_out: configurable timeout, set using an optional argument.

    Returns:
        :return: the IP address of the current node or a string ("Request timeout").
    
Create ICMP socket, send it and receive IP address of the current node.
After extracting the current node IP address from receiveOneTrace function,
we need to close the socket in order to cut the connection.
Create ICMP socket send it and receive IP address of the current node . After extracting the current node IP address from receiveOneTrace function we need to close the socket in order to cut the connection .
def do_three_trace(dest_addr, ttl, sequence, time_out):
    port_id = os.getpid()
    record_addr =""
    record = False
    for i in range(TIMES):
        client_socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, 1)  
        client_socket.setsockopt(socket.IPPROTO_IP, socket.IP_TTL, struct.pack('I', ttl))  
        client_socket.setsockopt(socket.SOL_SOCKET, socket.SO_RCVTIMEO, time_out)
        send_time = send_one_trace(client_socket, dest_addr, port_id, sequence)
        route_addr = receive_one_trace(client_socket, send_time, time_out)
        if route_addr != "Request timeout" :
            record = True
            record_addr = route_addr
        client_socket.close()
    if record is True:
        return record_addr
    else:
        return route_addr
def do_three_trace ( dest_addr , ttl , sequence , time_out ) : port_id = os . getpid ( ) record_addr = "" record = False for i in range ( TIMES ) : client_socket = socket . socket ( socket . AF_INET , socket . SOCK_RAW , 1 ) client_socket . setsockopt ( socket . IPPROTO_IP , socket . IP_TTL , struct . pack ( 'I' , ttl ) ) client_socket . setsockopt ( socket . SOL_SOCKET , socket . SO_RCVTIMEO , time_out ) send_time = send_one_trace ( client_socket , dest_addr , port_id , sequence ) route_addr = receive_one_trace ( client_socket , send_time , time_out ) if route_addr != "Request timeout" : record = True record_addr = route_addr client_socket . close ( ) if record is True : return record_addr else : return route_addr
Create ICMP socket, send it and receive IP address of the current node.
Create ICMP socket send it and receive IP address of the current node .
"""Create ICMP socket, send it and receive IP address of the current node.

    After extracting the current node IP address from receiveOneTrace function,
    we need to close the socket in order to cut the connection.

    Args:
        :param dest_addr: the IP address of the current node.
        :param ttl: Time To Live value.
        :param sequence: the nth times of the current node latency measurement.
        :param time_out: configurable timeout, set using an optional argument.

    Returns:
        :return: the IP address of the current node or a string ("Request timeout").
    """ # 1 is socket module constant associated with protocol ICMP. # icmp. # stop after ttl = 0 # 2. Call send_one_trace function. # 3. Call receive_one_trace function. # During [TIMES] times measurements, once we get real IP address then record it. # Else, return "Request timeout".
:return: the IP address of the current node or a string ("Request timeout").
: return : the IP address of the current node or a string ( " Request timeout " ) .
dest_addr
ttl
sequence
time_out
param time_out: configurable timeout, set using an optional argument.
param time_out : configurable timeout set using an optional argument .