From a37dd412e147c3f6b2fc77621d882c09558a962c Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Thu, 30 May 2024 23:07:36 +0200 Subject: [PATCH] netbrowse: add /netbrowse route and RESTCONF mDNS xlate Signed-off-by: Joachim Wiberg --- src/netbrowse/netbrowse/__init__.py | 8 ++++++-- src/netbrowse/netbrowse/mdns_hosts.py | 11 ++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/netbrowse/netbrowse/__init__.py b/src/netbrowse/netbrowse/__init__.py index ee498b8e..d0939052 100644 --- a/src/netbrowse/netbrowse/__init__.py +++ b/src/netbrowse/netbrowse/__init__.py @@ -2,25 +2,28 @@ """ Very basic mDNS scanner with HTML table renderer """ -from flask import Flask, render_template +from flask import Flask, render_template from .mdns_hosts import MdnsHosts __all__ = ['MdnsHosts'] app = Flask(__name__) + @app.route('/') +@app.route('/netbrowse') def index(): """The /browse or network.local application""" mdns_hosts = MdnsHosts() hosts_services = mdns_hosts.scan() - order = { 'HTTPS': 1, 'HTTP': 2, 'SSH': 3, 'SFTP': 4 } + order = {'HTTPS': 1, 'HTTP': 2, 'SSH': 3, 'SFTP': 4} for _, details in hosts_services.items(): details['services'].sort(key=lambda x: order.get(x['type'], 999)) return render_template('browse.html', hosts_services=hosts_services) + def main(): """Stand-alone running with Flask development server.""" try: @@ -28,5 +31,6 @@ def main(): except KeyboardInterrupt: print("Exiting") + if __name__ == '__main__': main() diff --git a/src/netbrowse/netbrowse/mdns_hosts.py b/src/netbrowse/netbrowse/mdns_hosts.py index 65535389..cc06cc72 100644 --- a/src/netbrowse/netbrowse/mdns_hosts.py +++ b/src/netbrowse/netbrowse/mdns_hosts.py @@ -17,11 +17,12 @@ class MdnsHosts: def scan(self): """Perform mDNS scan and return list of hosts.""" services = { - '_http._tcp': ('HTTP', 'http://{address}:{port}{path}'), - '_https._tcp': ('HTTPS', 'https://{address}:{port}{path}'), - '_netconf-ssh._tcp': ('NETCONF', None), - '_ssh._tcp': ('SSH', None), - '_sftp-ssh._tcp': ('SFTP', None), + '_http._tcp': ('HTTP', 'http://{address}:{port}{path}'), + '_https._tcp': ('HTTPS', 'https://{address}:{port}{path}'), + '_netconf-ssh._tcp': ('NETCONF', None), + '_restconf-tls._tcp': ('RESTCONF', None), + '_ssh._tcp': ('SSH', None), + '_sftp-ssh._tcp': ('SFTP', None), } result = subprocess.run(['avahi-browse', '-tarpk' if self.hask() else '-tarp'],