Python subprocess.DEVNULL Examples

The following are 30 code examples of subprocess.DEVNULL(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module subprocess , or try the search function .
Example #1
Source File: helper.py    From vidgear with Apache License 2.0 6 votes vote down vote up
def check_output(*args, **kwargs):
    """
    ### check_output

    Returns stdin output from subprocess module
    """
    # import libs
    import subprocess as sp
    from subprocess import DEVNULL

    # execute command in subprocess
    process = sp.Popen(stdout=sp.PIPE, stderr=DEVNULL, *args, **kwargs)
    output, unused_err = process.communicate()
    retcode = process.poll()

    # if error occurred raise error
    if retcode:
        cmd = kwargs.get("args")
        if cmd is None:
            cmd = args[0]
        error = sp.CalledProcessError(retcode, cmd)
        error.output = output
        raise error
    return output 
Example #2
Source File: test.py    From px with MIT License 6 votes vote down vote up
def remoteTest(port, fail=False):
    lip = 'echo $SSH_CLIENT ^| cut -d \\\" \\\" -f 1,1'
    cmd = os.getenv("REMOTE_SSH")
    if cmd is None:
        print("  Skipping: Remote test - REMOTE_SSH not set")
        return
    cmd = cmd + " curl --proxy `%s`:%s --connect-timeout 2 -s http://google.com" % (lip, port)
    sys.stdout.write("  Checking: Remote:" + str(port) + " = ")
    ret = subprocess.call(cmd, stdout=DEVNULL, stderr=DEVNULL)
    if (ret == 0 and fail == False) or (ret != 0 and fail == True) :
        print(str(ret) + ": Passed")
    else:
        print(str(ret) + ": Failed")
        return False

    return True 
Example #3
Source File: check_tap.py    From singer-tools with Apache License 2.0 6 votes vote down vote up
def run_and_summarize(tap, config, state=None, debug=False):
    cmd = [tap, '--config', config]
    if state:
        cmd += ['--state', state]
    print('Running command {}'.format(' '.join(cmd)))

    stderr = None if debug else subprocess.DEVNULL
    tap = Popen(cmd,
                stdout=subprocess.PIPE,
                stderr=stderr,
                bufsize=1,
                universal_newlines=True)
    summarizer = StdoutReader(tap)
    summarizer.start()
    returncode = tap.wait()
    if returncode != 0:
        print('ERROR: tap exited with status {}'.format(returncode))
        exit(1)

    return summarizer.summary 
Example #4
Source File: regtest.py    From btcpy with GNU Lesser General Public License v3.0 6 votes vote down vote up
def start_nodes(self):
        for node in self.nodes:
            data_dir = os.path.abspath('{}/node_{}'.format(self.regtest_path, node))
            conf = os.path.abspath('{}/bitcoin.conf'.format(data_dir))
            cmd = ['bitcoind', '-conf={}'.format(conf), '-datadir={}'.format(data_dir),
                   '-maxtxfee=1000', '-debug=1', '-prematurewitness', '-zmqpubrawblock=tcp://127.0.0.1:28332']
            # cmd = ['/home/rael/bitcoin/src/bitcoind', '-conf={}'.format(conf), '-datadir={}'.format(data_dir),
            #        '-maxtxfee=100', '-debug=1', '-prematurewitness']
            subprocess.call(cmd)  # , stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

            self.nodes[node] = {'user': Manager.user,
                                'password': Manager.password,
                                'host': Manager.host,
                                'port': Manager.base_port + node,
                                'rpcport': Manager.base_rpcport + node}

        sleep(3)

        for n in self.nodes:
            for m in self.nodes:
                if m != n:
                    self.send_rpc_cmd(['addnode',
                                       '{}:{}'.format(Manager.host, self.nodes[m]['port']),
                                       'onetry'],
                                      n) 
Example #5
Source File: engine_wrapper.py    From lichess-bot with GNU Affero General Public License v3.0 6 votes vote down vote up
def __init__(self, board, commands, options, silence_stderr=False):
        commands = commands[0] if len(commands) == 1 else commands
        self.go_commands = options.get("go_commands", {})

        self.engine = chess.uci.popen_engine(commands, stderr = subprocess.DEVNULL if silence_stderr else None)
        self.engine.uci()

        if options:
            self.engine.setoption(options)

        self.engine.setoption({
            "UCI_Variant": type(board).uci_variant,
            "UCI_Chess960": board.chess960
        })
        self.engine.position(board)

        info_handler = chess.uci.InfoHandler()
        self.engine.info_handlers.append(info_handler) 
Example #6
Source File: engine_wrapper.py    From lichess-bot with GNU Affero General Public License v3.0 6 votes vote down vote up
def __init__(self, board, commands, options=None, silence_stderr=False):
        commands = commands[0] if len(commands) == 1 else commands
        self.engine = chess.xboard.popen_engine(commands, stderr = subprocess.DEVNULL if silence_stderr else None)

        self.engine.xboard()

        if board.chess960:
            self.engine.send_variant("fischerandom")
        elif type(board).uci_variant != "chess":
            self.engine.send_variant(type(board).uci_variant)

        if options:
            self._handle_options(options)

        self.engine.setboard(board)

        post_handler = chess.xboard.PostHandler()
        self.engine.post_handlers.append(post_handler) 
Example #7
Source File: epr.py    From epr with MIT License 6 votes vote down vote up
def open_media(scr, epub, src):
    sfx = os.path.splitext(src)[1]
    fd, path = tempfile.mkstemp(suffix=sfx)
    try:
        with os.fdopen(fd, "wb") as tmp:
            tmp.write(epub.file.read(src))
        # run(VWR +" "+ path, shell=True)
        subprocess.call(
            VWR + [path],
            # shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL
        )
        k = scr.getch()
    finally:
        os.remove(path)
    return k 
Example #8
Source File: device.py    From Blueproximity with GNU General Public License v2.0 6 votes vote down vote up
def distance(self):
        '''
        Determinte distance of the device

        :return: distance of the device
        :rtype: int
        '''
        if not self.connected:
            logger.debug('Device disconnected -> reconnecting')
            self.connect()
        p = subprocess.run(
            ['hcitool', 'rssi', self.mac],
            stdout=subprocess.PIPE,
            stderr=subprocess.DEVNULL
        )
        if p.returncode == 0:
            match = rssi_re.match(p.stdout.decode('utf-8'))
            if match:
                return abs(int(match.group(1)))
        return 255 
Example #9
Source File: firefox_decrypt.py    From firefox_decrypt with GNU General Public License v3.0 6 votes vote down vote up
def get_version():
    """Obtain version information from git if available otherwise use
    the internal version number
    """
    def internal_version():
        return '.'.join(map(str, __version_info__[:3])) + ''.join(__version_info__[3:])

    try:
        p = Popen(["git", "describe", "--tags"], stdout=PIPE, stderr=DEVNULL)
    except OSError:
        return internal_version()

    stdout, stderr = p.communicate()

    if p.returncode:
        return internal_version()
    else:
        # Both py2 and py3 return bytes here
        return stdout.decode(USR_ENCODING).strip() 
Example #10
Source File: archive.py    From bob with GNU General Public License v3.0 6 votes vote down vote up
def _openDownloadFile(self, buildId, suffix):
        (tmpFd, tmpName) = mkstemp()
        url = self._makeUrl(buildId, suffix)
        try:
            os.close(tmpFd)
            env = { k:v for (k,v) in os.environ.items() if k in self.__whiteList }
            env["BOB_LOCAL_ARTIFACT"] = tmpName
            env["BOB_REMOTE_ARTIFACT"] = url
            ret = subprocess.call(["/bin/bash", "-ec", self.__downloadCmd],
                stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
                cwd="/tmp", env=env)
            if ret == 0:
                ret = tmpName
                tmpName = None
                return CustomDownloader(ret)
            else:
                raise ArtifactDownloadError("failed (exit {})".format(ret))
        finally:
            if tmpName is not None: os.unlink(tmpName) 
Example #11
Source File: system.py    From raveberry with GNU Lesser General Public License v3.0 6 votes vote down vote up
def get_latest_version(self, _request: WSGIRequest) -> HttpResponse:
        """Looks up the newest version number from PyPi and returns it."""
        try:
            subprocess.run(
                "pip3 install raveberry==nonexistingversion".split(),
                stdout=subprocess.DEVNULL,
                stderr=subprocess.PIPE,
                universal_newlines=True,
                check=True,
            )
        except subprocess.CalledProcessError as e:
            # parse the newest verson from pip output
            for line in e.stderr.splitlines():
                if "from versions" in line:
                    versions = [re.sub(r"[^0-9.]", "", token) for token in line.split()]
                    versions = [version for version in versions if version]
                    latest_version = versions[-1]
                    return HttpResponse(latest_version)
        return HttpResponseBadRequest("Could not determine latest version.") 
Example #12
Source File: util.py    From renpy-shader with MIT License 6 votes vote down vote up
def find_library(name):
            ename = re.escape(name)
            expr = r':-l%s\.\S+ => \S*/(lib%s\.\S+)' % (ename, ename)
            expr = os.fsencode(expr)

            try:
                proc = subprocess.Popen(('/sbin/ldconfig', '-r'),
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.DEVNULL)
            except OSError:  # E.g. command not found
                data = b''
            else:
                with proc:
                    data = proc.stdout.read()

            res = re.findall(expr, data)
            if not res:
                return _get_soname(_findLib_gcc(name))
            res.sort(key=_num_version)
            return os.fsdecode(res[-1]) 
Example #13
Source File: util.py    From renpy-shader with MIT License 6 votes vote down vote up
def _get_soname(f):
            # assuming GNU binutils / ELF
            if not f:
                return None
            objdump = shutil.which('objdump')
            if not objdump:
                # objdump is not available, give up
                return None

            try:
                proc = subprocess.Popen((objdump, '-p', '-j', '.dynamic', f),
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.DEVNULL)
            except OSError:  # E.g. bad executable
                return None
            with proc:
                dump = proc.stdout.read()
            res = re.search(br'\sSONAME\s+([^\s]+)', dump)
            if not res:
                return None
            return os.fsdecode(res.group(1)) 
Example #14
Source File: sound.py    From raveberry with GNU Lesser General Public License v3.0 6 votes vote down vote up
def set_output_device(self, request: WSGIRequest) -> HttpResponse:
        """Sets the given device as default output device."""
        device = request.POST.get("device")
        if not device:
            return HttpResponseBadRequest("No device selected")

        try:
            subprocess.run(
                ["pactl", "set-default-sink", device],
                stdout=subprocess.DEVNULL,
                stderr=subprocess.PIPE,
                env={"PULSE_SERVER": "127.0.0.1"},
                check=True,
            )
        except subprocess.CalledProcessError as e:
            return HttpResponseBadRequest(e.stderr)
        # restart mopidy to apply audio device change
        subprocess.call(["sudo", "/usr/local/sbin/raveberry/restart_mopidy"])
        return HttpResponse(
            f"Set default output. Restarting the current song might be necessary."
        ) 
Example #15
Source File: __init__.py    From benchexec with Apache License 2.0 6 votes vote down vote up
def write_table_in_format(template_format, outfile, options, **kwargs):
    callback = {"csv": write_csv_table, "html": htmltable.write_html_table}[
        template_format
    ]

    if outfile:
        # Force HTML file to be UTF-8 regardless of system encoding because it actually
        # declares itself to be UTF-8 in a meta tag.
        encoding = "utf-8" if template_format == "html" else None
        with open(outfile, "w", encoding=encoding) as out:
            callback(out, options=options, **kwargs)

        if options.show_table and template_format == "html":
            try:
                subprocess.Popen(
                    ["xdg-open", outfile],
                    stdout=subprocess.DEVNULL,
                    stderr=subprocess.DEVNULL,
                )
            except OSError:
                pass

    else:
        callback(sys.stdout, options=options, **kwargs) 
Example #16
Source File: smriprep_docker.py    From smriprep with Apache License 2.0 6 votes vote down vote up
def _run(args, stdout=None, stderr=None):
        from collections import namedtuple
        result = namedtuple('CompletedProcess', 'stdout stderr returncode')

        devnull = None
        if subprocess.DEVNULL in (stdout, stderr):
            devnull = open(os.devnull, 'r+')
            if stdout == subprocess.DEVNULL:
                stdout = devnull
            if stderr == subprocess.DEVNULL:
                stderr = devnull

        proc = subprocess.Popen(args, stdout=stdout, stderr=stderr)
        stdout, stderr = proc.communicate()
        res = result(stdout, stderr, proc.returncode)

        if devnull is not None:
            devnull.close()

        return res 
Example #17
Source File: disassemble.py    From wwrando with MIT License 6 votes vote down vote up
def disassemble_file(bin_path, asm_path):
  command = [
    r"C:\devkitPro\devkitPPC\bin\powerpc-eabi-objdump.exe",
    "--disassemble-zeroes",
    "-m", "powerpc",
    "-D",
    "-b", "binary",
    "-EB",
    bin_path
  ]
  
  print(" ".join(command))
  print()
  with open(asm_path, "wb") as f:
    result = call(command, stdout=f, stdin=DEVNULL, stderr=DEVNULL)
  if result != 0:
    raise Exception("Disassembler call failed") 
Example #18
Source File: plantumlcache.py    From codimension with GNU General Public License v3.0 6 votes vote down vote up
def run(self):
        """Runs plantUML"""
        srcFile = self.__fName[:-3] + 'txt'
        try:
            # Run plantUML
            saveToFile(srcFile, self.__source)
            retCode = subprocess.call(['java', '-jar', JAR_PATH,
                                       '-charset', 'utf-8', '-nometadata',
                                       srcFile],
                                      stdout=subprocess.DEVNULL,
                                      stderr=subprocess.DEVNULL)
            self.safeUnlink(srcFile)

            if retCode == 0:
                self.sigFinishedOK.emit(self.__md5, self.__uuid, self.__fName)
            else:
                self.sigFinishedError.emit(self.__md5, self.__fName)
        except Exception as exc:
            logging.error('Cannot render a plantUML diagram: %s', str(exc))
            self.safeUnlink(srcFile)
            self.sigFinishedError.emit(self.__md5, self.__fName) 
Example #19
Source File: dtest.py    From cassandra-dtest with Apache License 2.0 6 votes vote down vote up
def cleanup_docker_environment_before_test_execution():
    """
    perform a bunch of system cleanup operations, like kill any instances that might be
    hanging around incorrectly from a previous run, sync the disk, and clear swap.
    Ideally we would also drop the page cache, but as docker isn't running in privileged
    mode there is no way for us to do this.
    """
    # attempt to wack all existing running Cassandra processes forcefully to get us into a clean state
    p_kill = subprocess.Popen('ps aux | grep -ie CassandraDaemon | grep java | grep -v grep | awk \'{print $2}\' | xargs kill -9',
                              stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, shell=True)
    p_kill.wait(timeout=10)

    # explicitly call "sync" to flush everything that might be pending from a previous test
    # so tests are less likely to hit a very slow fsync during the test by starting from a 'known' state
    # note: to mitigate this further the docker image is mounting /tmp as a volume, which gives
    # us an ext4 mount which should talk directly to the underlying device on the host, skipping
    # the aufs pain that we get with anything else running in the docker image. Originally,
    # I had a timeout of 120 seconds (2 minutes), 300 seconds (5 minutes) but sync was still occasionally timing out.
    p_sync = subprocess.Popen('sudo /bin/sync', shell=True)
    p_sync.wait(timeout=600)

    # turn swap off and back on to make sure it's fully cleared if anything happened to swap
    # from a previous test run
    p_swap = subprocess.Popen('sudo /sbin/swapoff -a && sudo /sbin/swapon -a', shell=True)
    p_swap.wait(timeout=60) 
Example #20
Source File: player.py    From discord.py with MIT License 6 votes vote down vote up
def __init__(self, source, *, executable='ffmpeg', pipe=False, stderr=None, before_options=None, options=None):
        args = []
        subprocess_kwargs = {'stdin': source if pipe else subprocess.DEVNULL, 'stderr': stderr}

        if isinstance(before_options, str):
            args.extend(shlex.split(before_options))

        args.append('-i')
        args.append('-' if pipe else source)
        args.extend(('-f', 's16le', '-ar', '48000', '-ac', '2', '-loglevel', 'warning'))

        if isinstance(options, str):
            args.extend(shlex.split(options))

        args.append('pipe:1')

        super().__init__(source, executable=executable, args=args, **subprocess_kwargs) 
Example #21
Source File: util.py    From renpy-shader with MIT License 6 votes vote down vote up
def _get_soname(f):
            if not f:
                return None

            try:
                proc = subprocess.Popen(("/usr/ccs/bin/dump", "-Lpv", f),
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.DEVNULL)
            except OSError:  # E.g. command not found
                return None
            with proc:
                data = proc.stdout.read()
            res = re.search(br'\[.*\]\sSONAME\s+([^\s]+)', data)
            if not res:
                return None
            return os.fsdecode(res.group(1)) 
Example #22
Source File: video.py    From frigate with GNU Affero General Public License v3.0 6 votes vote down vote up
def start_or_restart_ffmpeg(ffmpeg_cmd, frame_size, ffmpeg_process=None):
    if not ffmpeg_process is None:
        print("Terminating the existing ffmpeg process...")
        ffmpeg_process.terminate()
        try:
            print("Waiting for ffmpeg to exit gracefully...")
            ffmpeg_process.communicate(timeout=30)
        except sp.TimeoutExpired:
            print("FFmpeg didnt exit. Force killing...")
            ffmpeg_process.kill()
            ffmpeg_process.communicate()
        ffmpeg_process = None

    print("Creating ffmpeg process...")
    print(" ".join(ffmpeg_cmd))
    process = sp.Popen(ffmpeg_cmd, stdout = sp.PIPE, stdin = sp.DEVNULL, bufsize=frame_size*10, start_new_session=True)
    return process 
Example #23
Source File: asciidoc2html.py    From qutebrowser with GNU General Public License v3.0 6 votes vote down vote up
def _get_asciidoc_cmd(self) -> List[str]:
        """Try to find out what commandline to use to invoke asciidoc."""
        if self._asciidoc is not None:
            return self._asciidoc

        for executable in ['asciidoc', 'asciidoc.py']:
            try:
                subprocess.run([executable, '--version'],
                               stdout=subprocess.DEVNULL,
                               stderr=subprocess.DEVNULL,
                               check=True)
            except OSError:
                pass
            else:
                return [executable]

        raise FileNotFoundError 
Example #24
Source File: addcrisprtypes.py    From phageParser with MIT License 5 votes vote down vote up
def hmmscan_genbank_files(gbdir='gbfiles', hmmdbpath='util/hmmercasdb/casdb'):
    hmm_outpath = os.path.join(gbdir, 'hmmeroutput')
    os.makedirs(hmm_outpath, exist_ok=True)
    print('Running hmmerscan on files in directory {}'.format(gbdir))
    for f in glob.glob(gbdir + '/*.gb'):
        accession = os.path.splitext(os.path.split(f)[1])[0]
        fastainput = convert_genbank_to_fasta(f).encode('utf-8')
        table_path = os.path.join(hmm_outpath, '{}.txt'.format(accession))
        commandargs = ['hmmscan', '--noali',
                       '--tblout', table_path, hmmdbpath, '-']
        subprocess.run(
            commandargs,
            input=fastainput,
            stdout=subprocess.DEVNULL
        ) 
Example #25
Source File: engine.py    From picochess with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, file: str, uci_shell: UciShell,  home=''):
        super(UciEngine, self).__init__()
        try:
            self.shell = uci_shell.get()
            if home:
                file = home + os.sep + file
            if self.shell:
                self.engine = chess.uci.spur_spawn_engine(self.shell, [file])
            else:
                self.engine = chess.uci.popen_engine(file, stderr=DEVNULL)

            self.file = file
            if self.engine:
                handler = Informer()
                self.engine.info_handlers.append(handler)
                self.engine.uci()
            else:
                logging.error('engine executable [%s] not found', file)
            self.options = {}
            self.future = None
            self.show_best = True

            self.res = None
            self.level_support = False
            self.installed_engines = read_engine_ini(self.shell, (file.rsplit(os.sep, 1))[0])

        except OSError:
            logging.exception('OS error in starting engine')
        except TypeError:
            logging.exception('engine executable not found') 
Example #26
Source File: testssl_mx_wrapper.py    From PrivacyScore with GNU General Public License v3.0 5 votes vote down vote up
def run_testssl(hostname: str) -> str:
    """Run testssl and ."""
    result_file = mktemp()

    call([
        TESTSSL_PATH,
        '-p', # enable all checks for presence of SSLx.x and TLSx.x protocols
        '-s', # tests certain lists of cipher suites by strength
        '-f', # checks (perfect) forward secrecy settings
        '-U', # tests all (of the following) vulnerabilities (if applicable)
        '-S', # displays the server's default picks and certificate info, e.g.
              # used CA, trust chain, Sig Alg, DNS CAA, OCSP Stapling
        '-P', # displays the server's picks: protocol+cipher, e.g., cipher
              # order, security of negotiated protocol and cipher
        '--jsonfile-pretty', result_file,
        '--warnings=batch',
        '--openssl-timeout', '10',
        '--sneaky', # use a harmless user agent instead of "SSL TESTER"
        '--fast', # skip some time-consuming checks
        '--ip', 'one', # do not scan all IPs returned by the DNS A query, but only the first one
        '-t', 'smtp', # test smtp
        '{}:25'.format(hostname), # hostname on port 25
    ], stdout=DEVNULL, stderr=DEVNULL)

    with open(result_file, 'r') as file:
        result = file.read()
    os.remove(result_file)
    return result 
Example #27
Source File: common.py    From PrivacyScore with GNU General Public License v3.0 5 votes vote down vote up
def _local_testssl(hostname: str, check_mx: bool) -> bytes:
    result_file = tempfile.mktemp()

    args = [
        TESTSSL_PATH,
        '-p', # enable all checks for presence of SSLx.x and TLSx.x protocols
        '-h', # enable all checks for security-relevant HTTP headers
        '-s', # tests certain lists of cipher suites by strength
        '-f', # checks (perfect) forward secrecy settings
        '-U', # tests all (of the following) vulnerabilities (if applicable)
        '-S', # displays the server's default picks and certificate info, e.g.
              # used CA, trust chain, Sig Alg, DNS CAA, OCSP Stapling
        '-P', # displays the server's picks: protocol+cipher, e.g., cipher
              # order, security of negotiated protocol and cipher
        '--jsonfile-pretty', result_file,
        '--warnings=off',
        '--openssl-timeout', '10',
        '--sneaky', # use a harmless user agent instead of "SSL TESTER"
        '--fast', # skip some time-consuming checks
        '--ip', 'one', # do not scan all IPs returned by the DNS A query, but only the first one
    ]
    if check_mx:
        args.remove('-h')
        args.extend([
            '-t', 'smtp',  # test smtp
            '{}:25'.format(hostname),  # hostname on port 25
        ])
    else:
        args.append(hostname)

    call(args, stdout=DEVNULL, stderr=DEVNULL)

    # exception when file does not exist.
    with open(result_file, 'rb') as file:
        result = file.read()
    # delete json file.
    os.remove(result_file)

    # store raw scan result
    return result 
Example #28
Source File: pytester.py    From python-netsurv with MIT License 5 votes vote down vote up
def _exec_lsof(self):
        pid = os.getpid()
        # py3: use subprocess.DEVNULL directly.
        with open(os.devnull, "wb") as devnull:
            return subprocess.check_output(
                ("lsof", "-Ffn0", "-p", str(pid)), stderr=devnull
            ).decode() 
Example #29
Source File: main.py    From wit with Apache License 2.0 5 votes vote down vote up
def get_git_version():
    # not an official release, use git to get an explicit version
    path = Path(__file__).resolve().parent.parent.parent
    log.spam("Running [git -C {} describe --tags --dirty]".format(str(path)))
    proc = subprocess.run(['git', '-C', str(path), 'describe', '--tags', '--dirty'],
                          stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
    version = proc.stdout.decode('utf-8').rstrip()
    log.spam("Output: [{}]".format(version))
    return re.sub(r"^v", "", version) 
Example #30
Source File: test.py    From px with MIT License 5 votes vote down vote up
def checkFilter(ips, port):
    def checkProc(lip, port):
        rcode = subprocess.call("curl --proxy " + lip + ":" + str(port) + " http://google.com",
            stdout=DEVNULL, stderr=DEVNULL)
        sys.stdout.write(str(rcode) + " ")
        if rcode == 0:
            return True
        elif rcode in [7, 52, 56]:
            return False
        else:
            print("Weird curl return " + str(rcode))
            sys.exit()

    return checkCommon(ips, port, checkProc)