User:Eleanorg/Thematic1.1/Make hops into %: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
No edit summary
 
Line 19: Line 19:
traceroute = os.popen(command,'r')            # popen function opens system command with argument 'r' for 'read'
traceroute = os.popen(command,'r')            # popen function opens system command with argument 'r' for 'read'
hopcount = float(traceroute.read()) - 1
hopcount = float(traceroute.read()) - 1
print(hopcount)
 


###--------- CONVERT TO %------------------
###--------- CONVERT TO %------------------

Latest revision as of 13:37, 13 December 2011

Converts hop count to %. 1 hop is around 2%, 30 or more is 75%.

traceroute default max hop count is 30; left unchanged here as tracing over 30 is sloooow, but 30 hops will be converted to 75% only - sites in far east etc often have over 50 hops from Europe!

  • Question - is there a way of getting a more accurate hopcount for sites with 30 or more hops, without having to go thru very slow traceroute count?
#!/usr/bin/python
#-*- coding:utf-8 -*-

import os				      # lets you use system commands inside the python script


###---------- GET NO. OF HOPS--------------

site = "mysite.org"
command = "traceroute " + site + " | wc -l"   # concatenates your site variable inside command to be sent to system
traceroute = os.popen(command,'r')            # popen function opens system command with argument 'r' for 'read'
hopcount = float(traceroute.read()) - 1


###--------- CONVERT TO %------------------

def makePercent():
  percent = hopcount / 40               
  return(percent)

print makePercent()