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

From XPUB & Lens-Based wiki
(Created page with "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 c...")
 
No edit summary
Line 15: Line 15:
###---------- GET NO. OF HOPS--------------
###---------- GET NO. OF HOPS--------------


site = "newint.org"
site = "mysite.org"
command = "traceroute " + site + " | wc -l"  # concatenates your site variable inside command to be sent to system
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'
traceroute = os.popen(command,'r')            # popen function opens system command with argument 'r' for 'read'

Revision as of 23:59, 2 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
print(hopcount)

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

percent = hopcount / 40                       
print(percent)