diff --git a/.archive/coro.py b/.archive/coro.py deleted file mode 100644 index 2e0b2e7..0000000 --- a/.archive/coro.py +++ /dev/null @@ -1,22 +0,0 @@ -import ipaddress as ip -import typing -import asyncio - -from findssh.coro import is_port_open - - -async def as_completed( - net: ip.IPv4Network, port: int, service: str, timeout: float -) -> typing.List[typing.Tuple[ip.IPv4Address, str]]: - futures = [is_port_open(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/.archive/findssh.m index f7acede..b9b2fb3 100644 --- a/.archive/findssh.m +++ b/.archive/findssh.m @@ -7,15 +7,11 @@ % example (find all SSH servers on IPv4 subnet on Port 22): % findssh() -assert(~verLessThan('matlab', '8.4'), 'Matlab >= R2014b required') - -if nargin < 1, port=22; end -if nargin < 2, service = ''; end -if nargin < 3, timeout = 0.1; end - -validateattributes(port, {'numeric'}, {'integer', 'nonnegative'}) -validateattributes(service, {'string', 'char'}, {'scalartext'}) -validateattributes(timeout, {'numeric'}, {'real', 'nonnegative'}) +arguments + port (1,1) {mustBeInteger, mustBePositive} = 22 + service (1,1) string = "" + timeout (1,1) {mustBeReal, mustBePositive} = 0.1 +end net = py.findssh.address2net(py.findssh.get_lan_ip()); diff --git a/src/findssh/coro.py b/src/findssh/coro.py index 0c3db26..ac748da 100644 --- a/src/findssh/coro.py +++ b/src/findssh/coro.py @@ -25,9 +25,8 @@ async def get_hosts( """ hosts = [] - for h in asyncio.as_completed( - [waiter(host, port, service, timeout) for host in net.hosts()] - ): + futures = [waiter(host, port, service, timeout) for host in net.hosts()] + for h in asyncio.as_completed(futures): if host := await h: print(host) hosts.append(host)