Exemplo n.º 1
0
def pidAndProcessNameHoldingPorts(portStart, portStop):
    output = SubprocessRunner.callAndReturnOutput(
            ["/bin/bash", "-c", "netstat -tulpn 2> /dev/null"],
            timeout = 5
            )

    if output is None:
        #the netstat subprocess must have timed out
        return None

    outputLines = output.split("\n")

    allOutputLinesMatching = []

    for port in range(portStart, portStop):
        for line in output.split("\n"):
            if (":" + str(port)) in line:
                allOutputLinesMatching.append(line)

    if not allOutputLinesMatching:
        return None

    for line in allOutputLinesMatching:
        match = re.match(r'.*LISTEN *([0-9]+)/(.*)', line)

        if match is not None:
            logging.warn("Found process: %s", line)

            pidToKill = int(match.group(1))
            processName = match.group(2)

            return pidToKill, processName

    return None
Exemplo n.º 2
0
def pidAndProcessNameHoldingPorts(portStart, portStop):
    output = SubprocessRunner.callAndReturnOutput(
        ["/bin/bash", "-c", "netstat -tulpn 2> /dev/null"], timeout=5)

    if output is None:
        #the netstat subprocess must have timed out
        return None

    outputLines = output.split("\n")

    allOutputLinesMatching = []

    for port in range(portStart, portStop):
        for line in output.split("\n"):
            if (":" + str(port)) in line:
                allOutputLinesMatching.append(line)

    if not allOutputLinesMatching:
        return None

    for line in allOutputLinesMatching:
        match = re.match(r'.*LISTEN *([0-9]+)/(.*)', line)

        if match is not None:
            logging.warn("Found process: %s", line)

            pidToKill = int(match.group(1))
            processName = match.group(2)

            return pidToKill, processName

    return None