mirror of
https://github.com/kernelkit/infix.git
synced 2026-08-01 05:13:01 +02:00
netbrowse: add /netbrowse route and RESTCONF mDNS xlate
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
committed by
Mattias Walström
parent
f9bbb86d49
commit
a37dd412e1
@@ -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()
|
||||
|
||||
@@ -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'],
|
||||
|
||||
Reference in New Issue
Block a user