Created
January 27, 2016 02:43
-
-
Save huangziwei/e4f47eb807a04e89ef88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from __future__ import print_function | |
# import commands | |
import subprocess | |
import sys | |
import numpy as np | |
from termcolor import colored | |
### Get result from `fping` | |
ping = subprocess.Popen('cat ips | fping -q -c 10', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) | |
result = np.array(ping.communicate()[1].split('\n')) | |
num_of_servers = len(result) - 1 | |
### Get a list of avg speeds of all servers | |
avg = [] | |
for i in range(num_of_servers): | |
avg.append(float(result[i].split(',')[-1].split('=')[-1].split('/')[1])) | |
#################################### | |
# Sorted from fastest to slowest, # | |
# And then highlight the first one # | |
#################################### | |
idx = np.argsort(avg) | |
num_of_report = 5 | |
print( "\nYou should try these {}:\n".format(num_of_report) ) | |
print( '\t' + colored(result[idx][0], 'green') ) | |
for i in range(1, num_of_report): | |
print( '\t' + result[idx][i] ) | |
print( "\n(* p1: PPTP; p2: L2TP)" ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment