#!/usr/bin/python
import os
import traceback
import subprocess
import json
from pprint import PrettyPrinter


def runTraceroute(ip):
    outDir = "scamperTraces/"
    if not os.path.exists(directory):
        os.makedirs(directory)

    outfileName=outDir+ip+"-paris-traceroute.warts"
    #TODO: Check if host country is same as destination country (No need to launch traceroutes for foreign AS)
    try:
        command="sudo -S scamper -o {0} -O warts -I \'trace -P icmp-paris -q 3 -Q {1}\' < .sudo.auth".format(outfileName,ip)
        os.system(command)
    except:
        traceback.print_exc()
        print("ERROR in traceroute.")
    return outfileName

if __name__ == "__main__":
    #fileName=runTraceroute('172.16.31.10')
    fileName=runTraceroute('192.168.3.11')
    lines = subprocess.check_output(["sc_warts2json", fileName],universal_newlines=True)
    print(len(lines))
    jsonData=json.loads(lines)
    pp=PrettyPrinter()
    pp.pprint(jsonData)
#!/usr/bin/python
import os
import traceback
import subprocess
import json
from pprint import PrettyPrinter


def runTraceroute(ip):
    outDir = "scamperTraces/"
    if not os.path.exists(directory):
        os.makedirs(directory)

    outfileName=outDir+ip+"-paris-traceroute.warts"
    #TODO: Check if host country is same as destination country (No need to launch traceroutes for foreign AS)
    try:
        command="sudo -S scamper -o {0} -O warts -I \'trace -P icmp-paris -q 3 -Q {1}\' < .sudo.auth".format(outfileName,ip)
        os.system(command)
    except:
        traceback.print_exc()
        print("ERROR in traceroute.")
    return outfileName

if __name__ == "__main__":
    #fileName=runTraceroute('172.16.31.10')
    fileName=runTraceroute('192.168.3.11')
    lines = subprocess.check_output(["sc_warts2json", fileName],universal_newlines=True)
    print(len(lines))
    jsonData=json.loads(lines)
    pp=PrettyPrinter()
    pp.pprint(jsonData)
#!/usr/bin/python #TODO: Check if host country is same as destination country (No need to launch traceroutes for foreign AS) #fileName=runTraceroute('172.16.31.10')