diff --git a/archive/coro.py b/archive/coro.py new file mode 100644 index 0000000..02d9843 --- /dev/null +++ b/archive/coro.py @@ -0,0 +1,23 @@ +import ipaddress as ip +import typing +import asyncio + +from findssh.coro import isportopen + + +async def as_completed(net: ip.IPv4Network, + port: int, + service: str, + timeout: float) -> typing.List[typing.Tuple[ip.IPv4Address, str]]: + futures = [isportopen(host, port, service) for host in net.hosts()] + hosts = [] + for future in asyncio.as_completed(futures, timeout=timeout): + try: + res = await future + except asyncio.TimeoutError: + continue + + if res is not None: + print(*res) + hosts.append(res) + return hosts diff --git a/archive/findssh.m b/findssh.m similarity index 79% rename from archive/findssh.m rename to findssh.m index 4bc81f7..93ee1ee 100644 --- a/archive/findssh.m +++ b/findssh.m @@ -17,9 +17,8 @@ validateattributes(service, {'string', 'char'}, {'scalartext'}) validateattributes(timeout, {'numeric'}, {'real', 'nonnegative'}) -% Matlab R2018b didn't like ThreadPoolExectutor -servers = py.findssh.main('', port, service, timeout); +net = py.findssh.netfromaddress(py.findssh.getLANip()); -hosts = cellfun(@char, cell(servers), 'uniformoutput', false); +hosts = cell(py.findssh.threadpool.get_hosts(net, uint8(port), service, timeout)); end diff --git a/tests/test_matlab.py b/tests/test_matlab.py new file mode 100644 index 0000000..4fdc48d --- /dev/null +++ b/tests/test_matlab.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import pytest +import subprocess +import shutil + +matlab = shutil.which('matlab') + + +@pytest.mark.skipif(matlab is None, reason='Matlab not found') +def test_matlab(): + no_python = subprocess.run([matlab, '-batch', 'exit(isempty(pyversion))'], timeout=60).returncode + + if no_python: + pytest.skip('python not setup in Matlab') + + ret = subprocess.check_output([matlab, '-batch', 'findssh'], + universal_newlines=True, timeout=60) + print(ret) + + +if __name__ == '__main__': + pytest.main(['-s', __file__])