Use traceroute{,6} on BSD instead of traceroute -{4,6}

This commit is contained in:
Baptiste Jonglez 2014-01-28 16:55:36 +01:00
parent 5cb45d5785
commit fe9a7f8fe4
1 changed files with 10 additions and 3 deletions

View File

@ -57,14 +57,21 @@ def check_accesslist():
def traceroute(): def traceroute():
check_accesslist() check_accesslist()
if sys.platform.startswith('freebsd') or sys.platform.startswith('netbsd') or sys.platform.startswith('openbsd'):
traceroute4 = [ 'traceroute' ]
traceroute6 = [ 'traceroute6' ]
else: # For Linux
traceroute4 = [ 'traceroute', '-4' ]
traceroute6 = [ 'traceroute', '-6' ]
src = [] src = []
if request.path == '/traceroute6': if request.path == '/traceroute6':
o = "-6" traceroute = traceroute6
if app.config.get("IPV6_SOURCE",""): if app.config.get("IPV6_SOURCE",""):
src = [ "-s", app.config.get("IPV6_SOURCE") ] src = [ "-s", app.config.get("IPV6_SOURCE") ]
else: else:
o = "-4" traceroute = traceroute4
if app.config.get("IPV4_SOURCE",""): if app.config.get("IPV4_SOURCE",""):
src = [ "-s", app.config.get("IPV4_SOURCE") ] src = [ "-s", app.config.get("IPV4_SOURCE") ]
@ -77,7 +84,7 @@ def traceroute():
options = [ '-A', '-q1', '-w1', '-m15' ] options = [ '-A', '-q1', '-w1', '-m15' ]
else: # For Linux else: # For Linux
options = [ '-A', '-q1', '-N32', '-w1', '-m15' ] options = [ '-A', '-q1', '-N32', '-w1', '-m15' ]
command = [ 'traceroute' , o ] + src + options + [ query ] command = traceroute + src + options + [ query ]
result = subprocess.Popen( command , stdout=subprocess.PIPE).communicate()[0].decode('utf-8', 'ignore').replace("\n","<br>") result = subprocess.Popen( command , stdout=subprocess.PIPE).communicate()[0].decode('utf-8', 'ignore').replace("\n","<br>")
return result return result