### Create an LDN Network Source: https://context7.com/kinnay/ldn/llms.txt Initializes a new network using the create_network async context manager. Requires valid prod.keys and game-specific parameters like local_communication_id and scene_id. ```python import ldn import trio import struct import random NICKNAME = "Host" LOCAL_COMMUNICATION_ID = 0x01009B90006DC000 # Super Mario Maker 2 SCENE_ID = 1 PASSWORD = b"LunchPack2DefaultPhrase" def make_application_data(): """Build game-specific application data (example for SMM2)""" data = bytearray() # PIA header data += struct.pack(" STANetwork ``` ```python async with create_network(param: CreateNetworkParam) -> APNetwork ``` -------------------------------- ### Load Encryption Keys Source: https://github.com/kinnay/ldn/blob/master/docs/reference/ldn.md Loads encryption keys from a prod.keys file, which can be dumped from a Switch device. ```python def load_keys(path: str) -> dict[str, bytes] ``` -------------------------------- ### Load Encryption Keys Source: https://github.com/kinnay/ldn/blob/master/docs/reference/ldn.md Loads encryption keys from a prod.keys file. ```APIDOC ## def load_keys ### Description Loads encryption keys from a `prod.keys` file. These can be dumped from a Switch device. ### Method GET ### Endpoint None (Function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters #### Path Parameters - **path** (str) - Required - The path to the `prod.keys` file. ### Response #### Success Response (200) - **dict[str, bytes]** - A dictionary containing the loaded encryption keys. #### Response Example ```json { "key1": "value1", "key2": "value2" } ``` ``` -------------------------------- ### Run script with root privileges Source: https://github.com/kinnay/ldn/wiki/Common-Issues Use this command to resolve permission errors or module access issues when running scripts as root. ```bash sudo -E python3 script.py ``` -------------------------------- ### Join an Existing LDN Network Source: https://context7.com/kinnay/ldn/llms.txt Use this snippet to join an existing LDN network. It first scans for suitable networks and then connects using provided parameters. Ensure you have your keys loaded. ```python import ldn import trio import socket LOCAL_COMMUNICATION_ID = 0x01009B90006DC000 # Super Mario Maker 2 SCENE_ID = 1 PASSWORD = b"LunchPack2DefaultPhrase" APPLICATION_VERSION = 6 NICKNAME = "Player1" async def join_network(): keys = ldn.load_keys("~/.switch/prod.keys") # First, scan for a suitable network networks = await ldn.scan(keys) target = None for network in networks: if (network.local_communication_id == LOCAL_COMMUNICATION_ID and network.scene_id == SCENE_ID and network.accept_policy != ldn.ACCEPT_NONE and network.num_participants < network.max_participants): target = network break if target is None: print("No suitable network found") return # Configure connection parameters param = ldn.ConnectNetworkParam() param.keys = keys param.network = target param.password = PASSWORD param.name = NICKNAME.encode() param.app_version = APPLICATION_VERSION param.platform = ldn.PLATFORM_NX # or PLATFORM_OUNCE for Switch 2 # Join the network async with ldn.connect(param) as network: print(f"Connected! IP: {network.participant().ip_address}") print(f"Broadcast address: {network.broadcast_address()}") # Listen for network events while True: event = await network.next_event() if isinstance(event, ldn.JoinEvent): print(f"{event.participant.name.decode()} joined at {event.participant.ip_address}") elif isinstance(event, ldn.LeaveEvent): print(f"{event.participant.name.decode()} left") elif isinstance(event, ldn.DisconnectEvent): print(f"Disconnected (reason: {event.reason})") break elif isinstance(event, ldn.ApplicationDataChanged): print(f"Application data changed: {len(event.new)} bytes") elif isinstance(event, ldn.AcceptPolicyChanged): print(f"Accept policy changed from {event.old} to {event.new}") trio.run(join_network) ``` -------------------------------- ### CreateNetworkParam Source: https://github.com/kinnay/ldn/blob/master/docs/reference/ldn.md Parameters for creating a new LDN network. The local_communication_id, scene_id, name, app_version, and keys fields are always required. ```APIDOC ## CreateNetworkParam ### Description Creates a new instance with the default values. The `local_communication_id`, `scene_id`, `name`, `app_version` and `keys` fields are always required. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **ifname** (str) - Optional - The interface name for the access point. The interface names must not already be in use. Defaults to "ldn". - **ifname_monitor** (str) - Optional - The interface name for the monitor. The interface names must not already be in use. Defaults to "ldn-mon". - **ifname_tap** (str) - Optional - A name for the TAP interface. The interface names must not already be in use. Defaults to "ldn-tap". - **phyname** (str) - Optional - The name of the wiphy on which the access point interface are created. Defaults to "phy0". - **phyname_monitor** (str) - Optional - The name of the wiphy on which the monitor interface is created. Defaults to "phy0". - **local_communication_id** (int) - Required - This is usually the title id. - **scene_id** (int) - Required - The game mode. - **max_participants** (int) - Optional - The maximum number of participants. Cannot be higher than 8. Defaults to 8. - **application_data** (bytes) - Optional - Game-specific data. Can be updated at any time after network creation. Defaults to b"" - **accept_policy** (int) - Optional - Specifies which stations are allowed to join the network. Must be one of the [`ACCEPT_`](#global-constants) constants. Defaults to ACCEPT_ALL. - **accept_filter** (list[MACAddress]) - Optional - This list contains a blacklist or whitelist, depending on the accept policy. Defaults to [] - **security_level** (int) - Optional - The security level of the network. Always `1` in practice. Defaults to 1. - **ssid** (bytes | None) - Optional - Must contain exactly 16 bytes. If `None`, a random SSID is generated during network creation. - **name** (bytes) - Required - Your nickname (up to 32 bytes). - **app_version** (int) - Required - Your application communication version. - **platform** (int) - Optional - The platform that you are playing on. Must be one of the [`PLATFORM_`](#global-constants) constants. Defaults to PLATFORM_NX. - **channel** (int | None) - Optional - The WLAN channel of the network. If `None`, the channel is chosen randomly from `1`, `6` or `11` during network creation. - **server_random** (bytes | None) - Optional - Must be 16 bytes. This is used to generate encryption keys. If `None`, a random key is generated during network creation. - **password** (bytes) - Optional - Password/passphrase. This is used to generate encryption keys. Defaults to b"" - **version** (int) - Optional - LDN version (`2`, `3` or `4`). Defaults to 4. - **enable_challenge** (bool) - Optional - Specifies whether the DRM challenge is enabled. This is always enabled for games, but not for system titles. Defaults to True. - **device_id** (int) - Optional - The device id for the DRM challenge. Defaults to a random integer. - **protocol** (int) - Optional - The protocol to use, must be 1 (NX) or 3. Defaults to 1. - **keys** (dict[str, bytes]) - Required - Encryption keys loaded from `prod.keys`. - **override_advertise_key** (bytes | None) - Optional - Overrides the key that is used to encrypt the advertisement frames. This is normally not required, but can be useful while researching new protocol versions. - **override_data_key** (bytes | None) - Optional - Overrides the key that is used to encrypt data frames. This is normally not required, but can be useful while researching new protocol versions. ### Request Example ```json { "local_communication_id": 12345, "scene_id": 1, "name": "Player1", "app_version": 1, "keys": { "prod.keys": "..." } } ``` ### Response (No specific response defined for this parameter object, it's used for network creation configuration.) ``` -------------------------------- ### Load Encryption Keys Source: https://context7.com/kinnay/ldn/llms.txt Loads encryption keys from a prod.keys file, which are necessary for all LDN network operations. Keys are loaded from the default location. ```python import ldn # Load encryption keys from the default location keys = ldn.load_keys("~/.switch/prod.keys") # The keys dictionary contains various encryption keys needed for LDN operations # Example keys include: master_key_00, master_key_12, aes_kek_generation_source, etc. print(f"Loaded {len(keys)} encryption keys") ``` -------------------------------- ### ConnectNetwork Parameters Source: https://github.com/kinnay/ldn/blob/master/docs/reference/ldn.md Parameters required for connecting to a network using the LDN library. ```APIDOC ## ConnectNetworkParam ### Description Parameters required for connecting to a network using the LDN library. The `network` and `keys` fields are always required. ### Initialization `__init__()` - Creates a new instance with the default values. ### Fields - **ifname** (str) - The interface name for the station. The interface names must not already be in use. Defaults to "ldn". - **phyname** (str) - The name of the wiphy on which the station interface is created. Defaults to "phy0". - **network** ([NetworkInfo](#networkinfo)) - The network information obtained during scanning. - **password** (bytes) - Password/passphrase. This is used to generate encryption keys. Authentication fails if the password is wrong. Defaults to b"" . - **name** (bytes) - Your nickname (up to 32 bytes). - **app_version** (int) - Your application communication version. - **platform** (int) - The platform that you are playing on. Must be one of the [`PLATFORM_`](#global-constants) constants. Defaults to PLATFORM_NX. - **enable_challenge** (bool) - Specifies whether the DRM challenge is enabled. This is always enabled for games, but not for system titles. Defaults to True. - **device_id** (int) - The device id for the DRM challenge. Defaults to a random integer between 0 and 0xFFFFFFFFFFFFFFFF. - **client_random** (bytes | None) - Must be 16 bytes. This is used during authentication. If `None`, a random value is generated automatically. - **keys** (dict[str, bytes]) - The keys that are loaded from `prod.keys`. These can be loaded from a file with the `load_keys` function. - **override_advertise_key** (bytes | None) - Overrides the key that is used to decrypt the advertisement frames. This is normally not required, but can be useful while researching new protocol versions. - **override_data_key** (bytes | None) - Overrides the key that is used to encrypt data frames. This is normally not required, but can be useful while researching new protocol versions. ``` -------------------------------- ### MACAddress Comparison and Representation Source: https://github.com/kinnay/ldn/blob/master/docs/reference/ldn.md Methods for comparing, hashing, and converting MAC address objects to different formats. ```python def __eq__(other: MACAddress) -> bool def __hash__() -> int def __bytes__() -> bytes def __str__() -> str def __repr__() -> str ``` -------------------------------- ### LDN Network Creation Source: https://github.com/kinnay/ldn/blob/master/docs/reference/ldn.md Creates a new LDN network. The network is automatically destroyed when exiting the `async with` block. ```APIDOC ## async with create_network ### Description Creates a new LDN network. The network is destroyed automatically at the end of the `async with` block. ### Method ASYNC WITH ### Endpoint None (Function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **param** ([CreateNetworkParam](#createnetworkparam)) - Required - Parameters for creating the network. ### Request Example ```json { "param": { "ssid": "MyNewNetwork", "password": "mynewpassword", "channel": 11, "protocol": 3, "max_participants": 4 } } ``` ### Response #### Success Response (200) - **[APNetwork](#apnetwork)** - An object representing the active access point network. #### Response Example ```json { "ssid": "MyNewNetwork", "mac_address": "12:34:56:78:9a:bc", "channel": 11, "protocol": 3, "max_participants": 4, "participants": [] } ``` ``` -------------------------------- ### Scan LDN Networks with Custom Parameters Source: https://context7.com/kinnay/ldn/llms.txt Customizes the LDN network scanning behavior by specifying interface names, channels, dwell time, and protocol versions. Allows filtering networks by game title ID. ```python import ldn import trio async def custom_scan(): keys = ldn.load_keys("~/.switch/prod.keys") # Scan with custom parameters networks = await ldn.scan( keys=keys, ifname="ldn", # Interface name for scanning phyname="phy0", # Physical wireless device channels=[1, 6, 11], # WLAN channels to scan dwell_time=0.110, # Time to wait on each channel (seconds) protocols=[1, 3] # Protocol versions (1=NX, 3=newer) ) # Filter networks by game title ID target_game = 0x01009B90006DC000 # Super Mario Maker 2 game_networks = [n for n in networks if n.local_communication_id == target_game] print(f"Found {len(game_networks)} Super Mario Maker 2 networks") return game_networks trio.run(custom_scan) ``` -------------------------------- ### NetworkInfo Structure Source: https://github.com/kinnay/ldn/blob/master/docs/reference/ldn.md Provides information about a local network, including communication IDs, versions, participant details, and network settings. ```APIDOC ## NetworkInfo ### Description Provides information about a local network, including communication IDs, versions, participant details, and network settings. ### Fields - **local_communication_id** (int) - This is usually the title id of the game. - **app_version** (int) - The application communication version of the host. - **scene_id** (int) - Scene id (defined by game). - **accept_policy** (int) - Defines which stations are accepted by the host. One of the [`ACCEPT_`](#global-constants) constants. - **max_participants** (int) - Maximum number of participants (up to 8). - **num_participants** (int) - Current number of connected participants. - **participants** (list[[ParticipantInfo](#participantinfo)]) - Current network participants. This list always contains exactly 8 entries. - **application_data** (bytes) - Additional information provided by game. - **address** ([MACAddress](#macaddress)) - The MAC address of the network host. - **band** (int) - The WLAN band of the network (2 or 5). - **channel** (int) - The WLAN channel of the network. - **ssid** (bytes) - The SSID of the network (16 random bytes). - **version** (int) - LDN version used by the host. - **server_random** (bytes) - Random bytes generated by the host. These are used to generate encryption keys. - **security_level** (int) - The security level of the network. ``` -------------------------------- ### Remove existing interfaces Source: https://github.com/kinnay/ldn/wiki/Common-Issues Use these commands to clean up interfaces if a script failed to shut down properly. ```bash sudo iw ldn del sudo iw ldn-mon del ``` -------------------------------- ### APNetwork - Event Handling and Station Management Source: https://github.com/kinnay/ldn/blob/master/docs/reference/ldn.md APIs for managing stations and handling network events. ```APIDOC ## APNetwork ### Description APIs for managing stations and handling network events. ### Methods #### `kick(index: int)` - **Description**: Kicks a station from the network. - **Parameters**: - `index` (int) - Required - The index of the station to kick. - **Returns**: `None` #### `next_event()` - **Description**: Waits until an event occurs and returns it. - **Returns**: `object` - Either [JoinEvent](#Joinevent) or [LeaveEvent](#leaveevent). ## Events ### JoinEvent - **Description**: Triggered when a new station joins the network. - **Fields**: - `index` (int) - The index of the joining participant. - `participant` ([ParticipantInfo](#participantinfo)) - Information about the joining participant. ### LeaveEvent - **Description**: Triggered when a station leaves the network. - **Fields**: - `index` (int) - The index of the leaving participant. - `participant` ([ParticipantInfo](#participantinfo)) - Information about the leaving participant. ### DisconnectEvent - **Description**: Triggered when you are disconnected from the network. - **Fields**: - `reason` (int) - The reason for disconnection. ### ApplicationDataChanged - **Description**: Triggered when the host has changed the application data. - **Fields**: - `old` (bytes) - The previous application data. - `new` (bytes) - The new application data. ### AcceptPolicyChanged - **Description**: Triggered when the host has changed the station accept policy. - **Fields**: - `old` (int) - The previous accept policy. - `new` (int) - The new accept policy. ``` -------------------------------- ### Inspect LDN Network Information Source: https://context7.com/kinnay/ldn/llms.txt Scans for nearby LDN networks and prints detailed information about each, including network identification, host details, protocol settings, and participant data. Requires loading keys and uses trio for asynchronous scanning. ```python import ldn import trio async def inspect_network(): keys = ldn.load_keys("~/.switch/prod.keys") networks = await ldn.scan(keys) for info in networks: # Network identification print(f"Local Communication ID: {info.local_communication_id:016x}") print(f"Scene ID: {info.scene_id}") print(f"SSID: {info.ssid.hex()}") # Host information print(f"Host Address: {info.address}") print(f"Band: {info.band} GHz") print(f"Channel: {info.channel}") # Protocol information print(f"LDN Version: {info.version}") print(f"Security Mode: {info.security_mode}") print(f"Protocol: {info.protocol}") # Participation settings print(f"Accept Policy: {info.accept_policy}") print(f"Max Participants: {info.max_participants}") print(f"Current Participants: {info.num_participants}") print(f"Application Data: {len(info.application_data)} bytes") # Participant details (always 8 slots) for i, p in enumerate(info.participants): if p.connected: print(f" Slot {i}: {p.name.decode()}") print(f" IP: {p.ip_address}") print(f" MAC: {p.mac_address}") print(f" App Version: {p.app_version}") platform = "NX" if p.platform == ldn.PLATFORM_NX else "Ounce" print(f" Platform: {platform}") trio.run(inspect_network) ``` -------------------------------- ### Handle LDN Authentication Errors Source: https://context7.com/kinnay/ldn/llms.txt Attempts to connect to an LDN network with incorrect credentials and handles potential `AuthenticationError` exceptions, printing the status code and its meaning. Requires loading keys and uses trio for asynchronous connection. ```python import ldn import trio # Authentication status codes AUTH_CODES = { 0: "SUCCESS", 1: "DENIED_BY_POLICY", 2: "MALFORMED_REQUEST", 3: "TIMEOUT", 4: "INVALID_VERSION", 5: "UNEXPECTED", 6: "CHALLENGE_FAILURE" } async def join_with_error_handling(): keys = ldn.load_keys("~/.switch/prod.keys") networks = await ldn.scan(keys) if not networks: print("No networks found") return param = ldn.ConnectNetworkParam() param.keys = keys param.network = networks[0] param.name = b"TestUser" param.app_version = 1 param.password = b"wrong_password" # Intentionally wrong try: async with ldn.connect(param) as network: print("Connected successfully") except ldn.AuthenticationError as e: print(f"Authentication failed: {AUTH_CODES.get(e.status_code, 'UNKNOWN')}") print(f"Status code: {e.status_code}") except ConnectionError as e: print(f"Connection error: {e}") trio.run(join_with_error_handling) ``` -------------------------------- ### ParticipantInfo Structure Source: https://github.com/kinnay/ldn/blob/master/docs/reference/ldn.md Contains information about a single participant in the network. ```APIDOC ## ParticipantInfo ### Description Contains information about a single participant in the network. ### Fields - **connected** (bool) - Indicates whether this entry is valid. - **ip_address** (str) - The IP address of the participant (169.254.X.Y). - **mac_address** ([MACAddress](#macaddress)) - The MAC address of the participant. - **name** (bytes) - The nickname of the participant. Defaults to b"" . - **app_version** (int) - The application communication version of the participant. Defaults to 0. - **platform** (int) - The platform that the participant is playing on. One of the [`PLATFORM_`](#global-constants) constants. ``` -------------------------------- ### Stop NetworkManager service Source: https://github.com/kinnay/ldn/wiki/Common-Issues Use this command to release the WLAN hardware when encountering device busy or network name conflicts. ```bash sudo service NetworkManager stop ``` -------------------------------- ### Receive UDP Packets on LDN Network Source: https://context7.com/kinnay/ldn/llms.txt This snippet demonstrates how to receive UDP packets on an LDN network after joining. It sets up a UDP socket bound to port 12345, which is commonly used for broadcast communication in LDN. Ensure you have joined a network before running this. ```python import ldn import trio import socket async def receive_game_packets(): keys = ldn.load_keys("~/.switch/prod.keys") networks = await ldn.scan(keys) if not networks: print("No networks found") return param = ldn.ConnectNetworkParam() param.keys = keys param.network = networks[0] param.name = b"Receiver" param.app_version = 1 async with ldn.connect(param) as network: print(f"Connected at {network.participant().ip_address}") # Create UDP socket for receiving broadcast packets sock = trio.socket.socket(socket.AF_INET, socket.SOCK_DGRAM) await sock.bind(("", 12345)) # LDN typically uses port 12345 async with trio.open_nursery() as nursery: async def packet_receiver(): while True: data, addr = await sock.recvfrom(4096) print(f"Received {len(data)} bytes from {addr}") async def event_handler(): while True: event = await network.next_event() if isinstance(event, ldn.DisconnectEvent): nursery.cancel_scope.cancel() break nursery.start_soon(packet_receiver) nursery.start_soon(event_handler) trio.run(receive_game_packets) ``` -------------------------------- ### STANetwork API Source: https://github.com/kinnay/ldn/blob/master/docs/reference/ldn.md Provides methods to retrieve information about the LDN network and its participants, and to handle network events. ```APIDOC ## STANetwork API ### Description Provides methods to retrieve information about the LDN network and its participants, and to handle network events. ### Methods #### `info()` - **Description**: Returns information about the network. - **Method**: GET - **Endpoint**: /STANetwork/info - **Response**: [NetworkInfo](#networkinfo) #### `participant()` - **Description**: Returns information about the local participant. - **Method**: GET - **Endpoint**: /STANetwork/participant - **Response**: [ParticipantInfo](#participantinfo) #### `broadcast_address()` - **Description**: Returns the broadcast address of the network. - **Method**: GET - **Endpoint**: /STANetwork/broadcast_address - **Response**: str #### `next_event()` - **Description**: Waits until an event occurs and returns it. Returns [JoinEvent](#Joinevent), [LeaveEvent](#leaveevent), [DisconnectEvent](#disconnected), [ApplicationDataChanged](#applicationdatachanged) or [AcceptPolicyChanged](#acceptpolicychanged). - **Method**: SUBSCRIBE - **Endpoint**: /STANetwork/next_event - **Response**: object (event type) ``` -------------------------------- ### Filter Network Participants by MAC Address Source: https://context7.com/kinnay/ldn/llms.txt Checks if a participant's MAC address is present in a blacklist. Ensure MAC addresses are correctly formatted. ```python blacklist = { ldn.MACAddress("aa:bb:cc:dd:ee:ff"), ldn.MACAddress("11:22:33:44:55:66") } participant_mac = ldn.MACAddress("aa:bb:cc:dd:ee:ff") if participant_mac in blacklist: print("Participant is blacklisted") ``` -------------------------------- ### APNetwork - Network Configuration Source: https://github.com/kinnay/ldn/blob/master/docs/reference/ldn.md Methods for configuring network settings such as application data, accept policy, and accept filter. ```APIDOC ## APNetwork ### Description Methods for configuring network settings such as application data, accept policy, and accept filter. ### Methods #### `set_application_data(data: bytes)` - **Description**: Updates the application data. - **Parameters**: - `data` (bytes) - Required - The new application data. - **Returns**: `None` #### `set_accept_policy(policy: int)` - **Description**: Updates the station accept policy. - **Parameters**: - `policy` (int) - Required - One of the [`ACCEPT_`](#global-constants) constants. - **Returns**: `None` #### `set_accept_filter(filter: list[[MACAddress](#macaddress)])` - **Description**: Updates the accept filter (blacklist or whitelist). - **Parameters**: - `filter` (list[[MACAddress](#macaddress)]) - Required - The list of MAC addresses for the filter. - **Returns**: `None` ``` -------------------------------- ### Scan for LDN Networks Source: https://github.com/kinnay/ldn/blob/master/docs/reference/ldn.md Searches for nearby LDN networks on specified WLAN channels. Requires a unique interface name and valid keys loaded via load_keys. ```python async def scan(keys: dict[str, bytes], ifname: str = "ldn", phyname: str = "phy0", channels: list[int] = [1, 6, 11], dwell_time: float=.110, protocols: list[int] = [1, 3]) -> list[NetworkInfo] ``` -------------------------------- ### LDN Network Connection Source: https://github.com/kinnay/ldn/blob/master/docs/reference/ldn.md Joins an active LDN network. The station is automatically disconnected when exiting the `async with` block. ```APIDOC ## async with connect ### Description Joins an active LDN network. The station is disconnected automatically at the end of the `async with` block. ### Method ASYNC WITH ### Endpoint None (Function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **param** ([ConnectNetworkParam](#connectnetworkparam)) - Required - Parameters for joining the network. ### Request Example ```json { "param": { "ssid": "MyNetwork", "password": "mypassword", "mac_address": "12:34:56:78:9a:bc", "channel": 6, "protocol": 1 } } ``` ### Response #### Success Response (200) - **[STANetwork](#stanetwork)** - An object representing the active station network. #### Response Example ```json { "ssid": "MyNetwork", "mac_address": "12:34:56:78:9a:bc", "channel": 6, "protocol": 1, "max_participants": 8, "participants": [ { "mac_address": "aa:bb:cc:dd:ee:ff", "nickname": "Player1" } ] } ``` ``` -------------------------------- ### Scan for Nearby LDN Networks Source: https://context7.com/kinnay/ldn/llms.txt Scans for nearby LDN networks on default WLAN channels (1, 6, 11 on 2.4GHz). Returns a list of NetworkInfo objects with details about discovered networks. ```python import ldn import trio async def scan_networks(): keys = ldn.load_keys("~/.switch/prod.keys") # Scan with default parameters (channels 1, 6, 11 on 2.4GHz) networks = await ldn.scan(keys) print(f"Found {len(networks)} network(s)") for network in networks: print(f"\nGame ID: {network.local_communication_id:016x}") print(f"Scene ID: {network.scene_id}") print(f"Host MAC: {network.address}") print(f"Channel: {network.channel} ({network.band} GHz)") print(f"Participants: {network.num_participants}/{network.max_participants}") # Check accept policy policies = { ldn.ACCEPT_ALL: "ALL", ldn.ACCEPT_NONE: "NONE", ldn.ACCEPT_BLACKLIST: "BLACKLIST", ldn.ACCEPT_WHITELIST: "WHITELIST" } print(f"Accept Policy: {policies[network.accept_policy]}") # List connected participants for participant in network.participants: if participant.connected: platform = "Switch" if participant.platform == ldn.PLATFORM_NX else "Switch 2" print(f" - {participant.name.decode()}: {participant.ip_address} ({platform})") trio.run(scan_networks) ``` -------------------------------- ### APNetwork - Network Information Source: https://github.com/kinnay/ldn/blob/master/docs/reference/ldn.md Provides methods to retrieve information about the LDN network and its participants. ```APIDOC ## APNetwork ### Description Provides methods to retrieve information about the LDN network and its participants. ### Methods #### `info()` - **Description**: Returns information about the network. - **Returns**: [NetworkInfo](#networkinfo) #### `participant()` - **Description**: Returns information about the local participant. - **Returns**: [ParticipantInfo](#participantinfo) #### `broadcast_address()` - **Description**: Returns the broadcast address of the network. - **Returns**: `str` ``` -------------------------------- ### LDN Network Scanning Source: https://github.com/kinnay/ldn/blob/master/docs/reference/ldn.md Scans for nearby LDN networks. This function creates a temporary interface and requires encryption keys. ```APIDOC ## async def scan ### Description Searches for nearby LDN networks on the given WLAN channels. To perform the scanning, this function creates a new interface on the given wiphy. The given interface name must not already be in use. The protocol should be 1 (NX) or 3. The `keys` can be read from a `prod.keys` file with the `load_keys` function. ### Parameters #### Path Parameters None #### Query Parameters - **ifname** (str) - Optional - The name of the interface to create. Defaults to "ldn". - **phyname** (str) - Optional - The name of the wiphy to use. Defaults to "phy0". - **channels** (list[int]) - Optional - A list of WLAN channels to scan. Defaults to [1, 6, 11]. - **dwell_time** (float) - Optional - The time to dwell on each channel in seconds. Defaults to 0.110. - **protocols** (list[int]) - Optional - A list of protocols to scan for. Defaults to [1, 3]. #### Request Body - **keys** (dict[str, bytes]) - Required - Encryption keys loaded from a prod.keys file. ### Response #### Success Response (200) - **list[[NetworkInfo](#networkinfo)]** - A list of NetworkInfo objects representing found networks. #### Response Example ```json [ { "ssid": "MyNetwork", "mac_address": "12:34:56:78:9a:bc", "channel": 6, "protocol": 1, "max_participants": 8 } ] ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.