network — network configuration
This module provides network drivers and routing configuration. To use this
module, a MicroPython variant/build with network capabilities must be installed.
Network drivers for specific hardware are available within this module and are
used to configure hardware network interface(s). Network services provided
by configured interfaces are then available for use via the socket
module.
Specific network class implementations
The following concrete classes implement the AbstractNIC interface and provide a way to control networking interfaces of various kinds.
Network functions
The following are functions available in the network module.
- network.country([code])
Get or set the two-letter ISO 3166-1 Alpha-2 country code to be used for radio compliance.
If the code parameter is provided, the country will be set to this value. If the function is called without parameters, it returns the current country.
The default code
"XX"represents the “worldwide” region.
- network.hostname([name])
Get or set the hostname that will identify this device on the network. It will be used by all interfaces.
- This hostname is used for:
Sending to the DHCP server in the client request. (If using DHCP)
Broadcasting via mDNS. (If enabled)
If the name parameter is provided, the hostname will be set to this value. If the function is called without parameters, it returns the current hostname.
A change in hostname is typically only applied during connection. For DHCP this is because the hostname is part of the DHCP client request, and the implementation of mDNS in most ports only initialises the hostname once during connection. For this reason, you must set the hostname before activating/connecting your network interfaces.
The length of the hostname is limited to 32 characters. MicroPython ports may choose to set a lower limit for memory reasons. If the given name does not fit, a
ValueErroris raised.The default hostname is typically the name of the board.
- network.ipconfig('param')
- network.ipconfig(param=value, ...)
Get or set global IP-configuration parameters. Supported parameters are the following (availability of a particular parameter depends on the port and the specific network interface):
dnsGet/set DNS server. This method can support both, IPv4 and IPv6 addresses.prefer(4/6) Specify which address type to return, if a domain name has both A and AAAA records. Note, that this does not clear the local DNS cache, so that any previously obtained addresses might not change.