zoukankan      html  css  js  c++  java
  • 探测web服务质量

    python脚本实现

    import os,sys
    import time
    import pycurl

    URL="http://192.168.1.1"
    c = pycurl.Curl()
    c.setopt(pycurl.URL,URL)
    c.setopt(pycurl.CONNECTTIMEOUT,5)
    c.setopt(pycurl.TIMEOUT,5)
    c.setopt(pycurl.NOPROGRESS,1)
    c.setopt(pycurl.FORBID_REUSE,1)
    c.setopt(pycurl.MAXREDIRS,1)
    c.setopt(pycurl.DNS_CACHE_TIMEOUT,30)
    indexfile = open(os.path.dirname(os.path.realpath(__file__))+"/context.txt","wb")
    c.setopt(pycurl.WRITEHEADER,indexfile)
    c.setopt(pycurl.WRITEDATA,indexfile)
    try:
    c.perform()
    except Exception,e:
    print "connection error:"+str(e)
    indexfile.close()
    c.close()
    sys.exit()
    NAMELOOKUP_TIME = c.getinfo(c.NAMELOOKUP_TIME)
    CONNECT_TIME = c.getinfo(c.CONNECT_TIME)
    PRETRANSFER_TIME = c.getinfo(c.PRETRANSFER_TIME)
    STARTTRANSFER_TIME = c.getinfo(c.STARTTRANSFER_TIME)
    TOTAL_TIME = c.getinfo(c.TOTAL_TIME)
    HTTP_CODE = c.getinfo(c.HTTP_CODE)
    SIZE_DOWNLOAD = c.getinfo(c.SIZE_DOWNLOAD)
    HEADER_SIZE = c.getinfo(c.HEADER_SIZE)
    SPEED_DOWNLOAD = c.getinfo(c.SPEED_DOWNLOAD)
    print "http status :%s" %(HTTP_CODE)
    print "dns shijian :%.2f ms" %(NAMELOOKUP_TIME*1000)
    print "jianlishijian :%.2f ms" %(CONNECT_TIME*1000)
    print "zhunbeichuanshushijian : %.2f ms" %(PRETRANSFER_TIME*1000)
    print "chuanshukaishijian : %.2f ms" %(STARTTRANSFER_TIME*1000)
    print "chuanshuzongshijian : %.2f ms" %(TOTAL_TIME*1000)
    print "xiazaishujubaodaxiao :%d kbytes/s" %(SIZE_DOWNLOAD/1024)
    print "http toubudaxiao :%d kbytes" %(HEADER_SIZE/1024)
    print "pingjunxiazaisudu: %d kbytes/s" %(SPEED_DOWNLOAD/1024)
    indexfile.close()
    c.close

  • 相关阅读:
    【BZOJ】4636: 蒟蒻的数列
    BZOJ1878 [SDOI2009]HH的项链
    【网络流24题----02】太空飞行计划
    【网络流24题----03】Air Raid最小路径覆盖
    【网络流24题----01】飞行员配对方案问题
    素数判定(米勒测试定理-费马小定理+快速乘)
    一堆模板(丑陋0.0)------数据结构
    丑数(USACO)
    NOI[2001]食物链
    关于Tarjan(2)
  • 原文地址:https://www.cnblogs.com/han1094/p/7306176.html
Copyright © 2011-2022 走看看