<gh_stars>0
import subprocess
import re

class Traceroute:
    def unixTraceroute(destination, iface = None, source = None):
        if iface != None and source != None:
            tracerouteProcess = subprocess.Popen(["sudo", "traceroute", destination, "-I", "-n", "-i", iface, "-s", source], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        else:
            tracerouteProcess = subprocess.Popen(["sudo", "traceroute", destination, "-I", "-n"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        tracerouteProcess.wait()
        out, err = tracerouteProcess.communicate()
        lines = out.decode("utf-8").split("\n")
        hops = []
        for line in lines[1:-1]:
            regexSearch = re.search(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', line)
            if(bool(regexSearch)):
                returnAddr = regexSearch.group()
                hops.append(returnAddr)
            else:
                hops.append("*")
        return hops