Пример #1
0
def get_delays(url):
  rd = []
  nd = []
  ad = []
  i = 0
  #Iterate 5 times
  while i<5:
    #tcpdump = subprocess.Popen('tcpdump \'tcp[13] & 2 != 0 \' -i eth0 -c 2 -ttt -n', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    p = pcapture.capture()
    p.filter('tcp[13] & 2 != 0')	#Only capture packets that contain a SYN flag 
    start = time.time()			#Before HTTP GET
    #Issue HTTP GET with a connect time out of 10 seconds and a read timeout of 10 seconds, and wait for process to finish
    wget = subprocess.Popen('wget --connect-timeout=10 --read-timeout=10 -O /dev/null %s'%url,shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    wget.wait()				
    end = time.time()			#After HTTP GET
    #readtcp = tcpdump.communicate()
    k = 0
    packet = ''
    while True:				#Look for a packet with a SYN flag only
      packet = p.next()
      if(packet != None):
	if len(packet)>2:
	  if type(packet[2]) == pycap.protocol.tcp:
	    if packet[2].flags == 2:
	      break
	   
    SYN = packet			
    while True:				#Look for a packet with  SYN+ACK flag
      packet = p.next()
      if(packet != None):
	if len(packet)>2:
	  if type(packet[2]) == pycap.protocol.tcp:
	    if packet[2].flags == 18:
	      break
    ACK = packet
    rd.append((end-start))		#RD portion of the Document Fetch Delay
    first = float(SYN[-1])		#SYN Packet time
    last = float(ACK[-1])		#SYN+ACK Packet Time
    SYNACK = (last-first)*1.0/1000	#Network Delay
    nd.append(SYNACK)
    start = time.time()			#Before HTTP HI
    #Issue HTTP HI (dummy) method with a maximum process time of 20 seconds, and wait for the process to finish. The no-keepalive ensures that persistent connection is off
    curl = subprocess.Popen('curl -m 20 --no-keepalive -sLX HI %s -o /dev/null'%url,shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    curl.wait()
    end = time.time()			#After HTTP HI
    ad.append((end-start))		#AD portion of the Processing Delay
    i+=1
    print 'done with iteration %d'%i
  delays = []
  dfd = []
  pd = []
  i = 0
  while i<5:
    dfd.append(rd[i]-nd[i])		#DFD = RD - ND
    pd.append(ad[i]-nd[i])		#PD = AD - ND
    i+=1
  delays.append(nd)
  delays.append(dfd)
  delays.append(pd)
  return delays
Пример #2
0
	Opts, Args = parser.parse_args()
	Opts.logfd = sys.stdout

	act = Action.instance()
	reqcache = HTTP_ReqCache(act)

	# timeout requests from the cache on a regular basis
	def check_cache(signum, _):
		reqcache.check(time.time())
	signal.signal(signal.SIGALRM, check_cache)
	signal.setitimer(signal.ITIMER_REAL, reqcache.max_age_sec, 1)

	capargs = opts2capargs(Opts)

	try:
		p = cap.capture(**capargs)
	except Exception as e:
		print e
		if 'no suitable device found' in str(e):
			if not hasattr(os, 'geteuid') or os.geteuid() != 0:
				print >> sys.stderr, 'try running as root'
		exit(1)
	try:
		while True:
			try:
				packet = p.next()
			except prot.error, e:
				print e
				continue
			# we assume HTTP will be: eth:ip:tcp:http:timestamp
			if not packet or len(packet) != 5:
Пример #3
0
from pycap import capture

cap = capture.capture('wlan0')
while True:
    aa = cap.next()
    try:
        if aa[1].version == 6:
            print aa[1].version
            import ipdb; ipdb.set_trace()
    except:
        pass