check_wan_latency.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:check_wan_latency 作者: computingbee 项目源码 文件源码
def getlat4city():
    avglat = -1

    sp_url = "http://www.super-ping.com/ping.php?node=" + CITY + "&ping=" + WAN_IP
    sp_refer_url = "http://www.super-ping.com/?ping=" + WAN_IP + "&locale=en"
        sp_http_headers = [ 'Referer: ' + sp_refer_url, 'X-Requested-With: XMLHttpRequest']

    crl = pyc.Curl()
    sio = StringIO()

    crl.setopt(pyc.URL, sp_url)
        crl.setopt(pyc.HTTPHEADER, sp_http_headers)
    crl.setopt(pyc.WRITEFUNCTION, sio.write)
    crl.perform()
    crl.close()

    lat_http_result = sio.getvalue() #process http result only if html
    if lat_http_result.strip() != "-" and lat_http_result.strip() != "super-ping.com":
        fstring="ping-avg'>"
        lstring="</div>"
        start = lat_http_result.index(fstring) + len(fstring)
        end = lat_http_result.index(lstring,start)
        avglat = lat_http_result[start:end]

    return float(avglat)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号