class LAN – control built-in Ethernet interfaces

This class provides a driver for Ethernet. Example usage:

import network

lan = network.LAN()

# We should have a valid IP now via DHCP


class network.LAN

Create a LAN network interface object.


Activate (“up”) or deactivate (“down”) network interface, if boolean argument is passed. Otherwise, query current state if no argument is provided. Most other methods require active interface.


  • 0: Link Down
  • 1: Link Join
  • 2: Link No-IP
  • 3: Link Up

Return the current status of the connection:

  • 0: Link Down
  • 1: Link Join
  • 2: Link No-IP
  • 3: Link Up

Returns True if the link is up and false if not.

LAN.ifconfig([(ip, subnet, gateway, dns)])

Get/set IP-level network interface parameters: IP address, subnet mask, gateway and DNS server. When called with no arguments, this method returns a 4-tuple with the above information. To set the above values, pass a 4-tuple with the required information. For example:

nic.ifconfig(('', '', '', ''))

For DHCP configuration do lan.ifconfig('dhcp') to get a DHCP IP.

LAN.config(param=value, ...)

Get or set general network interface parameters. These methods allow to work with additional parameters beyond standard IP configuration (as dealt with by LAN.ifconfig()). These include network-specific and hardware-specific parameters. For setting parameters, keyword argument syntax should be used, multiple parameters can be set at once. For querying, parameters name should be quoted as a string, and only one parameter can be queries at time:

# Set params
# Query params

Following are commonly supported parameters:

Parameter Description
mac MAC address (bytes)
trace Trace flags (int)

When trace flags are set the system will print debug information about packets on the ethernet link as they are transmitted or recieved. This may generate a lot of debug text…

  • 2 = TRACE_ETH_TX
  • 4 = TRACE_ETH_RX