Example #1
0
def pingIPSort(listIPs, myCount=1):
    # Setup dictionaries
    #
    pingResult = {}
    invalidIPs = []
    sortedIPs = {}

    # We now have a list of IPs. We sort them by fastest ping
    #
    for destIP in listIPs:
        # We now have a list of IPs. We sort them by fastest ping
        #
        avgTime = ping.quiet_ping(destIP, count=myCount)
        
        # Check to see if quient_ping return valid results
        #
        if (isinstance(avgTime, bool) == True) or avgTime[2] == 0:
            invalidIPs.append(destIP)
            # We skip adding this IP to the dictionary
            #
            continue

        # We add the avgTime to a list containing average IPs
        #
        pingResult[destIP] = avgTime[2]

    # Compute the sorted dictionary if we have valid IPs
    #
    sortedIPs = OrderedDict(sorted(pingResult.items()))

    return list(sortedIPs.keys()), str(invalidIPs)
Example #2
0
def pingOne(destIP, myCount=1):
    # Ping the machine passed
    #
    avgTime = ping.quiet_ping(destIP, count=myCount)

    # Check to see if quient_ping return valid results
    #
    if (isinstance(avgTime, bool) == True) or avgTime[2] == 0:
        return None

    # If we have a valid IP then return it
    #
    return avgTime[2]
Example #3
0
 def packetloss(server):
     return ping.quiet_ping(server, count=config.ping_count(), timeout=config.ping_timeout())[0]