Skip to content
This repository has been archived by the owner on Oct 1, 2021. It is now read-only.

Feature Request: Discover by default ports #146

Closed
danielperna84 opened this issue Sep 6, 2017 · 2 comments
Closed

Feature Request: Discover by default ports #146

danielperna84 opened this issue Sep 6, 2017 · 2 comments

Comments

@danielperna84
Copy link

danielperna84 commented Sep 6, 2017

I don't know if it has been discussed before, but I had the idea of discovering services by the ports they use by default. Is this a thing netdisco should do? The basic concept of what I mean:

#!/usr/bin/python3
import asyncio
import time

NOW = time.time()
DESTS = ["192.168.1.{}".format(i) for i in range(1, 255)]
PORTS = {
    1883: "mqtt",
    2000: "homematic-wired",
    2001: "homematic-wireless",
    2010: "homematic-ip",
    3306: "mysql",
    5432: "postgres",
    6466: "androidtv",
    8086: "influxdb",
    8883: "mqtts",
    # etc.
}

async def check_port(ip, port, loop):
    try:
        reader, writer = await asyncio.open_connection(ip, port, loop=loop)
        print(ip, port, PORTS[port])
        writer.close()
        return (ip, port, True)
    except:
        return (ip, port, False)

async def run(dests, ports, loop):
    tasks = [asyncio.ensure_future(check_port(d, p, loop)) for d in dests for p in ports]
    responses = await asyncio.gather(*tasks)
    return responses

LOOP = asyncio.get_event_loop()
FUTURE = asyncio.ensure_future(run(DESTS, PORTS.keys(), LOOP))
LOOP.run_until_complete(FUTURE)
print('#'*50)
print('Total time: ', time.time() - NOW)

(modified version of this)

It takes me ~130 seconds to scan my class C network, but the main relevant services actually show up rather quickly. I wouldn't go as far as expecting the results to be 100% accurate. But maybe services discovered this way could show a proposed HASS component (with link to documentation) that might work together with the discovered service.

That way especially newbies could be informed, that they have something that might be integrated into HASS, which they have not thought before because they haven't looked through all the components HASS supports. I would consider this a workaround for services which don't publish themselves via mDNS etc.

The question would be: do you think netdisco would be improved by using this approach?

@balloob
Copy link
Collaborator

balloob commented Sep 7, 2017

I think that we should limit netdisco to discovering things that want to be discovered (ie respond to some sort of discovery call)

@danielperna84
Copy link
Author

Ok. Then I'll close this issue. :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants