def measureDownloadSpeed(IDC, dataCenterIndex, resultArray, speedtestIndex,
                         searchListCount):
    localized_idc = util.getLocalizedIDC(IDC)
    localized_data_center = util.getLocalizedDataCenterArray(
        IDC)[dataCenterIndex]
    print(
        "节点:", localized_idc + " " + localized_data_center +
        "({0}/{1})".format(speedtestIndex + 1, searchListCount))
    url = util.loadUrlByArgs(IDC, dataCenterIndex)
    print("测试文件地址:", url)
    [timeSpent, dataDownload] = getDataCenterSpeed(url)
    resultArray.append([
        localized_idc, localized_data_center,
        dataDownload / timeSpent * downloadSpeedRefreshRate,
        util.getHostFromUrl(url)
    ])
Example #2
0
def handleList():
    if not args.list:
        return
    searchTable = pt.PrettyTable()
    searchTable.field_names = doPackList("服务商", "缩写", "节点位置", "节点编号", "节点域名",
                                         "节点链接")
    searchTable.align = 'l'
    searchTable.align["节点编号"] = 'r'
    for dataCenter in searchList:
        IDC = IDCs[dataCenter[0]]
        dataCenterIndex = dataCenter[1]
        DCUrl = util.loadUrlByArgs(IDC, dataCenterIndex)
        searchTable.add_row(
            doPackList(IDC['localized_idc'], IDC['idc'],
                       IDC['localized_data_center'][dataCenterIndex],
                       dataCenterIndex, util.getHostFromUrl(DCUrl), DCUrl))
    print(searchTable)
Example #3
0
for IDC in IDCs:
    if IDC['idc'] in sys.argv or IDC['localized_idc'] in sys.argv:
        if 'localized_idc' in IDC:
            localized_idc = IDC['localized_idc']
        else:
            localized_idc = IDC['idc']
        print("正在测试:", localized_idc)
        dataCenterCount = len(IDC['prefix'][0])
        for dataCenterIndex in range(0, dataCenterCount):
            if 'localized_data_center' in IDC:
                localized_data_center = IDC['localized_data_center'][
                    dataCenterIndex]
            else:
                localized_data_center = IDC['prefix'][0][dataCenterIndex]
            print("节点:", localized_data_center)
            url = util.loadUrlByArgs(IDC, dataCenterIndex)
            print("测试文件地址:", url)
            [timeSpent, dataDownload] = getDataCenterSpeed(url)
            resultArray.append([
                localized_idc, localized_data_center,
                dataDownload / timeSpent * downloadSpeedRefreshRate,
                util.getHostFromUrl(url)
            ])
resultArray.sort(key=functools.cmp_to_key(compareResultObject), reverse=True)
for row in resultArray:
    row[2] = prettifyUnit(row[2])
    resultTable.add_row(row)
print("\n\n\n\n\n")
print(resultTable)
Example #4
0
    if response.status_code == 200:
        info = json.loads(response.text)
        return " ".join(info[:-1]).strip()
    return None


IDCs = util.loadIDC()

for IDC in IDCs:
    IDCObject = IDCs[IDC]
    #检查IDC名称是否有翻译.
    if "localized_data_center" not in IDCObject:
        IDCObject["localized_data_center"] = []
        dataCenterCount = len(IDCObject['prefix'][0])
        #开始遍历数据中心.
        for dataCenterIndex in range(0, dataCenterCount):
            url = util.loadUrlByArgs(IDCObject, dataCenterIndex)
            ip = util.getIPFromHost(util.getHostFromUrl(url))
            unlocalizedName = IDCObject['prefix'][0][dataCenterIndex].strip()
            if ip:
                #IP解析成功,调用IPIP免费API.
                localizedName = getIPInfoFromIPIP(ip)
                if localizedName == None:
                    localizedName = unlocalizedName
                IDCObject["localized_data_center"].append(localizedName)
            else:
                #IP解析失败,使用英文名称.
                IDCObject["localized_data_center"].append(unlocalizedName)

util.saveIDC(IDCs)