Repository navigation
Add a local-only UniFi client and device export script - #14
Merged
Merged
Conversation
scripts/unifi_export.py logs in to a UniFi OS console (such as a UDM Pro) with a local account and writes every client and UniFi device the Network API returns as CSV or JSON. Standard library only; it talks only to the console's private or link-local IP address, never resolves names, ignores proxy settings, sets a hop limit, and pins the self-signed certificate by fingerprint. Secret fields are redacted and CSV cells are guarded against formula injection. Posted by Claude on behalf of @ShaneCurcuru Generated-by: Claude Code
Contributor
Author
|
Sufficient for basic purposes; returns a LOT of columns. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Shane · project thread
What
scripts/unifi_export.py: a standalone script (not Domus app code) that exports every client and UniFi network device known to a local UniFi OS console, such as a UDM Pro, as CSV or JSON, with every field the API returns.Source of the ask: Shane's message in the project thread. It may later feed an import of selected network devices into Domus, but nothing here touches
src/domus.Reading of the ask
api.ui.com), so I used the console's local Network API instead (/api/auth/login, then/proxy/network/api/self/sites,s/<site>/stat/sta,rest/user,stat/device), which returns far more fields than the cloud API and needs only a local username and password.scripts/, so ruff, pyright strict, and pytest already cover it. Happy to move it to a separatetools/directory if you'd rather keepscripts/for dev/CI helpers.--kind all);--include-offlineadds remembered clients that are not connected now.Local-only and security safeguards
--hostmust be an IP literal in 10/8, 172.16/12, 192.168/16, 169.254/16, fc00::/7, or fe80::/10. Hostnames are refused so no DNS query is ever made; public, loopback, CGNAT, and documentation ranges are refused (ipaddress.is_privatealone was too loose).http.clientdirectly: no proxy env vars, no redirects followed, no other host contacted, no telemetry.--max-hops, default 1), so a console behind another router will not answer; our own source address must also be local.--fingerprintpins the console's self-signed cert (SHA-256, constant-time compare);--show-fingerprintprints it without sending credentials;--ca-file(+--tls-name) or an explicit--insecureare the alternatives. TLS 1.2 minimum.--username/--password, or~/unifi.txt(key = value: host, username, password, fingerprint), else a getpass prompt. Warns if the file is group/world readable or owned by another user. Passwords never appear in output, errors, orrepr; bad credential lines are reported by number, not echoed.x_authkey,x_vwirekey,x_aes_gcm, passphrases, PSKs, tokens) are[REDACTED]unless--no-redact.= + - @are prefixed with'(client hostnames are attacker-controlled). Output files are created mode 0600. Responses over 64 MB are refused.Dependencies
None added: standard library only.
Tests
tests/test_unifi_export.py, 63 tests with a fake transport, fake sockets, and fake TLS; no network.ruff check,ruff format --check,pyright(strict), and the fullpytestsuite pass (536 passed, 1 skipped as before).I also ran the real
HTTPSTransportend to end against a throwaway local HTTPS server with a self-signed cert (outside the test suite): pinned fingerprint succeeds, a wrong fingerprint and an unpinned self-signed cert both fail with the guidance messages.Not done / not verified
--show-fingerprintthen a CSV export on your network./proxy/network/integration/v1, API-key auth) is not used: it needs an API key rather than username/password and returns fewer fields. It could be added as an option later.Posted by Claude on behalf of @ShaneCurcuru
Generated by Claude Code