All checks were successful
buildbot/nix-build .#checks.aarch64-darwin.nixos-test_install_machine Build done.
buildbot/nix-build .#checks.aarch64-darwin.nixos-flash-installer Build done.
buildbot/nix-build .#checks.aarch64-darwin.nixos-iso-installer Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-test_install_machine Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-app-no-breakpoints Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-flash-installer Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-iso-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-ts-api Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-cli-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-apk Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-age Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-deb Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-archlinux Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-rpm Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-bash Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-e2fsprogs Build done.
buildbot/nix-build .#checks.x86_64-linux.package-module-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-fakeroot Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-git Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-test-backup Build done.
buildbot/nix-build .#checks.aarch64-darwin.nixos-test-backup Build done.
buildbot/nix-build .#checks.x86_64-linux.renderClanOptions Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-nix Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-webview-ui Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-openssh Build done.
buildbot/nix-build .#checks.x86_64-linux.check-for-breakpoints Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-cli Build done.
buildbot/nix-build .#checks.x86_64-linux.package-default Build done.
buildbot/nix-build .#checks.x86_64-linux."clan-dep-python3.11-mypy" Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-rsync Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-sops Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-sshpass Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-tor Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-zbar Build done.
buildbot/nix-build .#checks.x86_64-linux."clan-dep-python3.11-qemu" Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-test-backup Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-clan-cli Build done.
buildbot/nix-build .#checks.x86_64-linux.lib-jsonschema-example-valid Build done.
buildbot/nix-build .#checks.x86_64-linux.container Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-default Build done.
buildbot/nix-build .#checks.x86_64-linux.borgbackup Build done.
buildbot/nix-build .#checks.x86_64-linux.deltachat Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-app-pytest Build done.
buildbot/nix-build .#checks.x86_64-linux.matrix-synapse Build done.
buildbot/nix-build .#checks.x86_64-linux.package-editor Build done.
buildbot/nix-build .#checks.x86_64-linux.package-impure-checks Build done.
buildbot/nix-build .#checks.x86_64-linux.package-deploy-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.module-schema Build done.
buildbot/nix-build .#checks.x86_64-linux.lib-jsonschema-nix-unit-tests Build done.
buildbot/nix-build .#checks.x86_64-linux.treefmt Build done.
buildbot/nix-build .#checks.x86_64-linux.package-moonlight-sunshine-accept Build done.
buildbot/nix-build .#checks.x86_64-linux.package-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.package-pending-reviews Build done.
buildbot/nix-build .#checks.x86_64-linux.package-tea-create-pr Build done.
buildbot/nix-build .#checks.x86_64-linux.package-merge-after-ci Build done.
buildbot/nix-build .#checks.x86_64-linux.package-zerotier-members Build done.
buildbot/nix-build .#checks.x86_64-linux.package-zt-tcp-relay Build done.
buildbot/nix-build .#checks.x86_64-linux.package-zerotierone Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-test_install_machine Build done.
buildbot/nix-build .#checks.x86_64-linux.postgresql Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-flash-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.package-module-schema Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-iso-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.secrets Build done.
buildbot/nix-build .#checks.x86_64-linux.zt-tcp-relay Build done.
buildbot/nix-build .#checks.x86_64-linux.package-iso-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.template-minimal Build done.
buildbot/nix-build .#checks.x86_64-linux.wayland-proxy-virtwl Build done.
buildbot/nix-build .#checks.x86_64-linux.package-function-schema Build done.
buildbot/nix-build .#checks.x86_64-linux.package-webview-ui Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-app Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-pytest-with-core Build done.
buildbot/nix-build .#checks.x86_64-linux.test-backups Build done.
buildbot/nix-build .#checks.x86_64-linux.syncthing Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-clan-app Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-pytest-without-core Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-install-test-ubuntu-22-04 Build done.
checks / checks-impure (pull_request) Successful in 2m15s
buildbot/nix-build .#checks.x86_64-linux.flash Build done.
buildbot/nix-build .#checks.x86_64-linux.test-installation Build done.
buildbot/nix-eval Build done.
117 lines
3.0 KiB
Python
117 lines
3.0 KiB
Python
import argparse
|
|
import re
|
|
from dataclasses import dataclass
|
|
|
|
from clan_cli.cmd import run_no_stdout
|
|
from clan_cli.nix import nix_shell
|
|
|
|
from . import API
|
|
|
|
|
|
@dataclass
|
|
class Host:
|
|
# Part of the discovery
|
|
interface: str
|
|
protocol: str
|
|
name: str
|
|
type_: str
|
|
domain: str
|
|
# Optional, only if more data is available
|
|
host: str | None
|
|
ip: str | None
|
|
port: str | None
|
|
txt: str | None
|
|
|
|
|
|
@dataclass
|
|
class DNSInfo:
|
|
""" "
|
|
mDNS/DNS-SD services discovered on the network
|
|
"""
|
|
|
|
services: dict[str, Host]
|
|
|
|
|
|
def decode_escapes(s: str) -> str:
|
|
return re.sub(r"\\(\d{3})", lambda x: chr(int(x.group(1))), s)
|
|
|
|
|
|
def parse_avahi_output(output: str) -> DNSInfo:
|
|
dns_info = DNSInfo(services={})
|
|
for line in output.splitlines():
|
|
parts = line.split(";")
|
|
# New service discovered
|
|
# print(parts)
|
|
if parts[0] == "+" and len(parts) >= 6:
|
|
interface, protocol, name, type_, domain = parts[1:6]
|
|
|
|
name = decode_escapes(name)
|
|
|
|
dns_info.services[name] = Host(
|
|
interface=interface,
|
|
protocol=protocol,
|
|
name=name,
|
|
type_=decode_escapes(type_),
|
|
domain=domain,
|
|
host=None,
|
|
ip=None,
|
|
port=None,
|
|
txt=None,
|
|
)
|
|
|
|
# Resolved more data for already discovered services
|
|
elif parts[0] == "=" and len(parts) >= 9:
|
|
interface, protocol, name, type_, domain, host, ip, port = parts[1:9]
|
|
|
|
name = decode_escapes(name)
|
|
|
|
if name in dns_info.services:
|
|
dns_info.services[name].host = decode_escapes(host)
|
|
dns_info.services[name].ip = ip
|
|
dns_info.services[name].port = port
|
|
if len(parts) > 9:
|
|
dns_info.services[name].txt = decode_escapes(parts[9])
|
|
else:
|
|
dns_info.services[name] = Host(
|
|
interface=parts[1],
|
|
protocol=parts[2],
|
|
name=name,
|
|
type_=decode_escapes(parts[4]),
|
|
domain=parts[5],
|
|
host=decode_escapes(parts[6]),
|
|
ip=parts[7],
|
|
port=parts[8],
|
|
txt=decode_escapes(parts[9]) if len(parts) > 9 else None,
|
|
)
|
|
|
|
return dns_info
|
|
|
|
|
|
@API.register
|
|
def show_mdns() -> DNSInfo:
|
|
cmd = nix_shell(
|
|
["nixpkgs#avahi"],
|
|
[
|
|
"avahi-browse",
|
|
"--all",
|
|
"--resolve",
|
|
"--parsable",
|
|
"-l", # Ignore local services
|
|
"--terminate",
|
|
],
|
|
)
|
|
proc = run_no_stdout(cmd)
|
|
data = parse_avahi_output(proc.stdout)
|
|
|
|
return data
|
|
|
|
|
|
def mdns_command(args: argparse.Namespace) -> None:
|
|
dns_info = show_mdns()
|
|
for name, info in dns_info.services.items():
|
|
print(f"Hostname: {name} - ip: {info.ip}")
|
|
|
|
|
|
def register_mdns(parser: argparse.ArgumentParser) -> None:
|
|
parser.set_defaults(func=mdns_command)
|