def do_one(myStats, destIP, hostname, timeout, mySeqNumber, packet_size, quiet=False):
    """
    Returns either the delay (in ms) or None on timeout.
    """
    delay = None

    try:  # One could use UDP here, but it's obscure
        mySocket = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.getprotobyname("icmp"))
    except socket.error as e:
        print("failed. (socket error: '%s')" % e.args[1])
        raise  # raise the original error

    my_ID = os.getpid() & 0xFFFF

    sentTime = send_one_ping(mySocket, destIP, my_ID, mySeqNumber, packet_size)
    if sentTime == None:
        mySocket.close()
        return delay

    myStats.pktsSent += 1

    recvTime, dataSize, iphSrcIP, icmpSeqNumber, iphTTL = receive_one_ping(mySocket, my_ID, timeout)

    mySocket.close()

    if recvTime:
        delay = (recvTime - sentTime) * 1000
        if not quiet:
            print("%d bytes from %s: icmp_seq=%d ttl=%d time=%d ms" % (
                dataSize, socket.inet_ntoa(struct.pack("!I", iphSrcIP)), icmpSeqNumber, iphTTL, delay)
                  )
        myStats.pktsRcvd += 1
        myStats.totTime += delay
        if myStats.minTime > delay:
            myStats.minTime = delay
        if myStats.maxTime < delay:
            myStats.maxTime = delay
    else:
        delay = None
        print("Request timed out.")

    return delay
def do_one ( myStats , destIP , hostname , timeout , mySeqNumber , packet_size , quiet = False ) : delay = None try : mySocket = socket . socket ( socket . AF_INET , socket . SOCK_RAW , socket . getprotobyname ( "icmp" ) ) except socket . error as e : print ( "failed. (socket error: '%s')" % e . args [ 1 ] ) raise my_ID = os . getpid ( ) & 0xFFFF sentTime = send_one_ping ( mySocket , destIP , my_ID , mySeqNumber , packet_size ) if sentTime == None : mySocket . close ( ) return delay myStats . pktsSent += 1 recvTime , dataSize , iphSrcIP , icmpSeqNumber , iphTTL = receive_one_ping ( mySocket , my_ID , timeout ) mySocket . close ( ) if recvTime : delay = ( recvTime - sentTime ) * 1000 if not quiet : print ( "%d bytes from %s: icmp_seq=%d ttl=%d time=%d ms" % ( dataSize , socket . inet_ntoa ( struct . pack ( "!I" , iphSrcIP ) ) , icmpSeqNumber , iphTTL , delay ) ) myStats . pktsRcvd += 1 myStats . totTime += delay if myStats . minTime > delay : myStats . minTime = delay if myStats . maxTime < delay : myStats . maxTime = delay else : delay = None print ( "Request timed out." ) return delay
Returns either the delay (in ms) or None on timeout.