ICMP Ping/ICMPPing.py
def do_one_ping(dest_addr, timeout, sequence):
    """Create ICMP socket and then send, receive packets of the same size.

    After getting the delay time from receiveOnePing function, we need to close
    the socket in order to cut the connection.

    Args:
        :param dest_addr: the IP address of the destination host.
        :param timeout: configurable timeout, set using an optional argument.
        :param sequence: the n times of ping.

    Returns:
        :return: the delay time between the socket send and receive a packet.
    """
    port_id = os.getpid()  # get current process id.
    # 1. Create ICMP socket
    # 1 is socket module constant associated with protocol ICMP.
    icmp_socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, 1)
    # Set the timeout value for the socket.
    icmp_socket.setsockopt(socket.SOL_SOCKET, socket.SO_RCVTIMEO, timeout)
    # 2. Call sendOnePing function.
    send_time = send_one_ping(icmp_socket, dest_addr, port_id, sequence)
    # 3. Call receiveOnePing function.
    receive_data = receive_one_ping(icmp_socket, port_id, timeout, send_time)
    # 4. Close ICMP socket.
    icmp_socket.close()
    # 5. Return delay information.
    return receive_data
Create ICMP socket and then send, receive packets of the same size.

    After getting the delay time from receiveOnePing function, we need to close
    the socket in order to cut the connection.

    Args:
        :param dest_addr: the IP address of the destination host.
        :param timeout: configurable timeout, set using an optional argument.
        :param sequence: the n times of ping.

    Returns:
        :return: the delay time between the socket send and receive a packet.
    
Create ICMP socket and then send, receive packets of the same size.
After getting the delay time from receiveOnePing function, we need to close
the socket in order to cut the connection.
Create ICMP socket and then send receive packets of the same size . After getting the delay time from receiveOnePing function we need to close the socket in order to cut the connection .
def do_one_ping(dest_addr, timeout, sequence):
    port_id = os.getpid()  
    icmp_socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, 1)
    icmp_socket.setsockopt(socket.SOL_SOCKET, socket.SO_RCVTIMEO, timeout)
    send_time = send_one_ping(icmp_socket, dest_addr, port_id, sequence)
    receive_data = receive_one_ping(icmp_socket, port_id, timeout, send_time)
    icmp_socket.close()
    return receive_data
def do_one_ping ( dest_addr , timeout , sequence ) : port_id = os . getpid ( ) icmp_socket = socket . socket ( socket . AF_INET , socket . SOCK_RAW , 1 ) icmp_socket . setsockopt ( socket . SOL_SOCKET , socket . SO_RCVTIMEO , timeout ) send_time = send_one_ping ( icmp_socket , dest_addr , port_id , sequence ) receive_data = receive_one_ping ( icmp_socket , port_id , timeout , send_time ) icmp_socket . close ( ) return receive_data
Create ICMP socket and then send, receive packets of the same size.
Create ICMP socket and then send receive packets of the same size .
"""Create ICMP socket and then send, receive packets of the same size.

    After getting the delay time from receiveOnePing function, we need to close
    the socket in order to cut the connection.

    Args:
        :param dest_addr: the IP address of the destination host.
        :param timeout: configurable timeout, set using an optional argument.
        :param sequence: the n times of ping.

    Returns:
        :return: the delay time between the socket send and receive a packet.
    """ # get current process id. # 1. Create ICMP socket # 1 is socket module constant associated with protocol ICMP. # Set the timeout value for the socket. # 2. Call sendOnePing function. # 3. Call receiveOnePing function. # 4. Close ICMP socket. # 5. Return delay information.
:return: the delay time between the socket send and receive a packet.
: return : the delay time between the socket send and receive a packet .
dest_addr
timeout
sequence
param sequence: the n times of ping.
param sequence : the n times of ping .