Ejemplo n.º 1
0
def find_all_devs(capmethod=0):
    """
    @param capmethod 0 for standard method, 1 for virtual interface,
                     2 for tcpdump/windump, 3 for dumpcap helper.
    @return a list containing VirtualIFace objects
    """

    if capmethod == 1:
        # This is virtual interface so the list will contain a dummy
        # VirtualIFace entry
        return [
            VirtualIFace('dummy', 'Virtual interface for reading file',
                         '0.0.0.0')
        ]

    if WINDOWS and (capmethod == 2 or capmethod == 3):
        # Ok here we have to get the stdout of %helper% -D
        if capmethod == 2:
            helper = Prefs()['backend.tcpdump'].value
        else:
            helper = Prefs()['backend.dumpcap'].value

        try:
            ret = []

            helper = subprocess.Popen(helper + " -D", stdout=subprocess.PIPE)
            output, _ = helper.communicate()

            for line in output.splitlines():
                name, desc = line.rsplit("(", 1)

                name = name.replace(" ", "")
                desc = desc[:-1]

                ret.append(VirtualIFace(name, desc, 'N/A'))

            return ret
        except Exception, err:
            log.error("Error in running the helper: %s" % str(err))
            return []
Ejemplo n.º 2
0
def find_all_devs(capmethod=0):
    """
    @param capmethod 0 for standard method, 1 for virtual interface,
                     2 for tcpdump/windump, 3 for dumpcap helper.
    @return a list containing VirtualIFace objects
    """

    if capmethod == 1:
        # This is virtual interface so the list will contain a dummy
        # VirtualIFace entry
        return [VirtualIFace('dummy',
                             'Virtual interface for reading file',
                             '0.0.0.0')]

    if WINDOWS and (capmethod == 2 or capmethod == 3):
        # Ok here we have to get the stdout of %helper% -D
        if capmethod == 2:
            helper = Prefs()['backend.tcpdump'].value
        else:
            helper = Prefs()['backend.dumpcap'].value

        try:
            ret = []

            helper = subprocess.Popen(helper + " -D", stdout=subprocess.PIPE)
            output, _ = helper.communicate()

            for line in output.splitlines():
                name, desc = line.rsplit("(", 1)

                name = name.replace(" ", "")
                desc = desc[:-1]

                ret.append(VirtualIFace(name, desc, 'N/A'))

            return ret
        except Exception, err:
            log.error("Error in running the helper: %s" % str(err))
            return []