Skip to content

Commit d6b76f3

Browse files
committed
docs: Update docs to replace ifconfig with ipconfig.
Signed-off-by: Felix Dörre <felix@dogcraft.de>
1 parent 88513d1 commit d6b76f3

File tree

12 files changed

+87
-48
lines changed

12 files changed

+87
-48
lines changed

docs/esp32/quickref.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ The :mod:`network` module::
8989
wlan.isconnected() # check if the station is connected to an AP
9090
wlan.connect('ssid', 'key') # connect to an AP
9191
wlan.config('mac') # get the interface's MAC address
92-
wlan.ifconfig() # get the interface's IP/netmask/gw/DNS addresses
92+
wlan.ipconfig('addr4') # get the interface's IPv4 addresses
9393

9494
ap = network.WLAN(network.AP_IF) # create access-point interface
9595
ap.config(ssid='ESP-AP') # set the SSID of the access point
@@ -107,7 +107,7 @@ A useful function for connecting to your local WiFi network is::
107107
wlan.connect('ssid', 'key')
108108
while not wlan.isconnected():
109109
pass
110-
print('network config:', wlan.ifconfig())
110+
print('network config:', wlan.ipconfig('addr4'))
111111

112112
Once the network is established the :mod:`socket <socket>` module can be used
113113
to create and use TCP/UDP sockets as usual, and the ``requests`` module for
@@ -130,7 +130,7 @@ To use the wired interfaces one has to specify the pins and mode ::
130130

131131
lan = network.LAN(mdc=PIN_MDC, ...) # Set the pin and mode configuration
132132
lan.active(True) # activate the interface
133-
lan.ifconfig() # get the interface's IP/netmask/gw/DNS addresses
133+
lan.ipconfig('addr4') # get the interface's IPv4 addresses
134134

135135

136136
The keyword arguments for the constructor defining the PHY type and interface are:

docs/esp8266/quickref.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ The :mod:`network` module::
5959
wlan.isconnected() # check if the station is connected to an AP
6060
wlan.connect('ssid', 'key') # connect to an AP
6161
wlan.config('mac') # get the interface's MAC address
62-
wlan.ifconfig() # get the interface's IP/netmask/gw/DNS addresses
62+
wlan.ipconfig('addr4') # get the interface's IPv4 addresses
6363

6464
ap = network.WLAN(network.AP_IF) # create access-point interface
6565
ap.active(True) # activate the interface
@@ -76,7 +76,7 @@ A useful function for connecting to your local WiFi network is::
7676
wlan.connect('ssid', 'key')
7777
while not wlan.isconnected():
7878
pass
79-
print('network config:', wlan.ifconfig())
79+
print('network config:', wlan.ipconfig('addr4'))
8080

8181
Once the network is established the :mod:`socket <socket>` module can be used
8282
to create and use TCP/UDP sockets as usual.

docs/esp8266/tutorial/network_basics.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ You can check if the interfaces are active by::
1919

2020
You can also check the network settings of the interface by::
2121

22-
>>> ap_if.ifconfig()
23-
('192.168.4.1', '255.255.255.0', '192.168.4.1', '8.8.8.8')
22+
>>> ap_if.ipconfig('addr4')
23+
('192.168.4.1', '255.255.255.0')
2424

25-
The returned values are: IP address, netmask, gateway, DNS.
25+
The returned values are: IP address and netmask.
2626

2727
Configuration of the WiFi
2828
-------------------------
@@ -45,8 +45,8 @@ To check if the connection is established use::
4545

4646
Once established you can check the IP address::
4747

48-
>>> sta_if.ifconfig()
49-
('192.168.0.2', '255.255.255.0', '192.168.0.1', '8.8.8.8')
48+
>>> sta_if.ipconfig('addr4')
49+
('192.168.0.2', '255.255.255.0')
5050

5151
You can then disable the access-point interface if you no longer need it::
5252

@@ -64,7 +64,7 @@ connect to your WiFi network::
6464
sta_if.connect('<ssid>', '<key>')
6565
while not sta_if.isconnected():
6666
pass
67-
print('network config:', sta_if.ifconfig())
67+
print('network config:', sta_if.ipconfig('addr4'))
6868

6969
Sockets
7070
-------

docs/library/network.LAN.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Example usage::
1010

1111
import network
1212
nic = network.LAN(0)
13-
print(nic.ifconfig())
13+
print(nic.ipconfig("addr4"))
1414

1515
# now use socket as usual
1616
...

docs/library/network.WIZNET5K.rst

+2-15
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Example usage::
1313

1414
import network
1515
nic = network.WIZNET5K(pyb.SPI(1), pyb.Pin.board.X5, pyb.Pin.board.X4)
16-
print(nic.ifconfig())
16+
print(nic.ipconfig("addr4"))
1717

1818
# now use socket as usual
1919
...
@@ -51,20 +51,7 @@ Constructors
5151
Methods
5252
-------
5353

54-
.. method:: WIZNET5K.isconnected()
55-
56-
Returns ``True`` if the physical Ethernet link is connected and up.
57-
Returns ``False`` otherwise.
58-
59-
.. method:: WIZNET5K.ifconfig([(ip, subnet, gateway, dns)])
60-
61-
Get/set IP address, subnet mask, gateway and DNS.
62-
63-
When called with no arguments, this method returns a 4-tuple with the above information.
64-
65-
To set the above values, pass a 4-tuple with the required information. For example::
66-
67-
nic.ifconfig(('192.168.0.4', '255.255.255.0', '192.168.0.1', '8.8.8.8'))
54+
This class implements most methods from `AbstractNIC <AbstractNIC>`, which are documented there. Additional methods are:
6855

6956
.. method:: WIZNET5K.regs()
7057

docs/library/network.WLAN.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Methods
107107

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

docs/library/network.WLANWiPy.rst

+4-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This class provides a driver for the WiFi network processor in the WiPy. Example
2020
wlan.connect('your-ssid', auth=(WLAN.WPA2, 'your-key'))
2121
while not wlan.isconnected():
2222
time.sleep_ms(50)
23-
print(wlan.ifconfig())
23+
print(wlan.ipconfig("addr4"))
2424

2525
# now use socket as usual
2626
...
@@ -96,16 +96,10 @@ Methods
9696
In case of STA mode, returns ``True`` if connected to a WiFi access point and has a valid IP address.
9797
In AP mode returns ``True`` when a station is connected, ``False`` otherwise.
9898

99-
.. method:: WLANWiPy.ifconfig(if_id=0, config=['dhcp' or configtuple])
99+
.. method:: WlanWiPy.ipconfig('param')
100+
WlanWiPy.ipconfig(param=value, ...)
100101

101-
With no parameters given returns a 4-tuple of *(ip, subnet_mask, gateway, DNS_server)*.
102-
103-
if ``'dhcp'`` is passed as a parameter then the DHCP client is enabled and the IP params
104-
are negotiated with the AP.
105-
106-
If the 4-tuple config is given then a static IP is configured. For instance::
107-
108-
wlan.ifconfig(config=('192.168.0.4', '255.255.255.0', '192.168.0.1', '8.8.8.8'))
102+
See :ref:`AbstractNIC.ipconfig <AbstractNIC.ipconfig>`. Supported parameters are: ``dhcp4``, ``addr4``, ``gw4``.
109103

110104
.. method:: WLANWiPy.mode([mode])
111105

docs/library/network.rst

+59-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ For example::
2424
print("Waiting for connection...")
2525
while not nic.isconnected():
2626
time.sleep(1)
27-
print(nic.ifconfig())
27+
print(nic.ipconfig("addr4"))
2828

2929
# now use socket as usual
3030
import socket
@@ -35,6 +35,8 @@ For example::
3535
data = s.recv(1000)
3636
s.close()
3737

38+
.. _AbstractnNIC:
39+
3840
Common network adapter interface
3941
================================
4042

@@ -113,8 +115,49 @@ parameter should be `id`.
113115
connected to the AP. The list contains tuples of the form
114116
(MAC, RSSI).
115117

118+
.. _AbstractNIC.ipconfig:
119+
.. method:: AbstractNIC.ipconfig('param')
120+
AbstractNIC.ipconfig(param=value, ...)
121+
122+
Get or set interface-specific IP-configuration interface parameters.
123+
Supported parameters are the following (availability of a particular
124+
parameter depends on the port and the specific network interface):
125+
126+
* ``dhcp4`` (``True/False``) obtain an IPv4 address, gateway and dns
127+
server via DHCP. This method does not block and wait for an address
128+
to be obtained. To check if an address was obtained, use the read-only
129+
property ``has_dhcp4``.
130+
* ``gw4`` Get/set the IPv4 default-gateway.
131+
* ``dhcp6`` (``True/False``) obtain a DNS server via stateless DHCPv6.
132+
Obtaining IP Addresses via DHCPv6 is currently not implemented.
133+
* ``autoconf6`` (``True/False``) obtain a stateless IPv6 address via
134+
the network prefix shared in router advertisements. To check if a
135+
stateless address was obtained, use the read-only
136+
property ``has_autoconf6``.
137+
* ``addr4`` (e.g. ``192.168.0.4/24``) obtain the current IPv4 address
138+
and network mask as ``(ip, subnet)``-tuple, regardless of how this
139+
address was obtained. This method can be used to set a static IPv4
140+
address either as ``(ip, subnet)``-tuple or in CIDR-notation.
141+
* ``addr6`` (e.g. ``fe80::1234:5678``) obtain a list of current IPv6
142+
addresses as ``(ip, state, preferred_lifetime, valid_lifetime)``-tuple.
143+
This include link-local, slaac and static addresses.
144+
``preferred_lifetime`` and ``valid_lifetime`` represent the remaining
145+
valid and preferred lifetime of each IPv6 address, in seconds.
146+
``state`` indicates the current state of the address:
147+
148+
* ``0x08`` - ``0x0f`` indicates the address is tentative, counting the
149+
number of probes sent.
150+
* ``0x10`` The address is deprecated (but still valid)
151+
* ``0x30`` The address is preferred (and valid)
152+
* ``0x40`` The address is duplicated and can not be used.
153+
154+
This method can be used to set a static IPv6
155+
address, by setting this parameter to the address, like ``fe80::1234:5678``.
156+
116157
.. method:: AbstractNIC.ifconfig([(ip, subnet, gateway, dns)])
117158

159+
.. note:: This function is deprecated, use `ipconfig()` instead.
160+
118161
Get/set IP-level network interface parameters: IP address, subnet mask,
119162
gateway and DNS server. When called with no arguments, this method returns
120163
a 4-tuple with the above information. To set the above values, pass a
@@ -127,7 +170,7 @@ parameter should be `id`.
127170

128171
Get or set general network interface parameters. These methods allow to work
129172
with additional parameters beyond standard IP configuration (as dealt with by
130-
`ifconfig()`). These include network-specific and hardware-specific
173+
`ipconfig()`). These include network-specific and hardware-specific
131174
parameters. For setting parameters, the keyword argument
132175
syntax should be used, and multiple parameters can be set at once. For
133176
querying, a parameter name should be quoted as a string, and only one
@@ -195,6 +238,20 @@ The following are functions available in the network module.
195238

196239
The default hostname is typically the name of the board.
197240

241+
.. function:: ipconfig('param')
242+
ipconfig(param=value, ...)
243+
244+
Get or set global IP-configuration parameters.
245+
Supported parameters are the following (availability of a particular
246+
parameter depends on the port and the specific network interface):
247+
248+
* ``dns`` Get/set DNS server. This method can support both, IPv4 and
249+
IPv6 addresses.
250+
* ``prefer`` (``4/6``) Specify which address type to return, if a domain
251+
name has both A and AAAA records. Note, that this does not clear the
252+
local DNS cache, so that any previously obtained addresses might not
253+
change.
254+
198255
.. function:: phy_mode([mode])
199256

200257
Get or set the PHY mode.

docs/mimxrt/quickref.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ Ethernet. Example usage::
528528
lan.active(True)
529529

530530
If there is a DHCP server in the LAN, the IP address is supplied by that server.
531-
Otherwise, the IP address can be set with lan.ifconfig(). The default address
531+
Otherwise, the IP address can be set with lan.ipconfig(addr4="..."). The default address
532532
is 192.168.0.1.
533533

534534
Teensy 4.1 does not have an Ethernet jack on the board, but PJRC offers an

docs/reference/mpremote.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,9 @@ An example ``config.py`` might look like:
469469
for ap in wl.scan():
470470
print(ap)
471471
""",], # Print out nearby WiFi networks.
472-
"wl_ifconfig": [
472+
"wl_ipconfig": [
473473
"exec",
474-
"import network; sta_if = network.WLAN(network.STA_IF); print(sta_if.ifconfig())",
474+
"import network; sta_if = network.WLAN(network.STA_IF); print(sta_if.ipconfig('addr4'))",
475475
""",], # Print ip address of station interface.
476476
"test": ["mount", ".", "exec", "import test"], # Mount current directory and run test.py.
477477
"demo": ["run", "path/to/demo.py"], # Execute demo.py on the device.

docs/wipy/quickref.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -184,18 +184,18 @@ WLAN (WiFi)
184184

185185
See :ref:`network.WLAN <network.WLAN>` and :mod:`machine`. ::
186186

187-
import machine
187+
import machine, network
188188
from network import WLAN
189189

190190
# configure the WLAN subsystem in station mode (the default is AP)
191191
wlan = WLAN(mode=WLAN.STA)
192192
# go for fixed IP settings
193-
wlan.ifconfig(config=('192.168.0.107', '255.255.255.0', '192.168.0.1', '8.8.8.8'))
193+
network.ipconfig(dns='8.8.8.8')
194+
wlan.ipconfig(addr4='192.168.0.107/24', gw4='192.168.0.1')
194195
wlan.scan() # scan for available networks
195196
wlan.connect(ssid='mynetwork', auth=(WLAN.WPA2, 'mynetworkkey'))
196197
while not wlan.isconnected():
197198
pass
198-
print(wlan.ifconfig())
199199
# enable wake on WLAN
200200
wlan.irq(trigger=WLAN.ANY_EVENT, wake=machine.SLEEP)
201201
# go to sleep

docs/wipy/tutorial/wlan.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,15 @@ Assigning a static IP address when booting
5050
If you want your WiPy to connect to your home router after boot-up, and with a fixed
5151
IP address so that you can access it via telnet or FTP, use the following script as /flash/boot.py::
5252

53-
import machine
53+
import machine, network
5454
from network import WLAN
5555
wlan = WLAN() # get current object, without changing the mode
5656

5757
if machine.reset_cause() != machine.SOFT_RESET:
5858
wlan.init(WLAN.STA)
5959
# configuration below MUST match your home router settings!!
60-
wlan.ifconfig(config=('192.168.178.107', '255.255.255.0', '192.168.178.1', '8.8.8.8'))
60+
network.ipconfig(dns='8.8.8.8')
61+
wlan.ipconfig(addr4='192.168.0.107/24', gw4='192.168.0.1')
6162

6263
if not wlan.isconnected():
6364
# change the line below to match your network ssid, security and password

0 commit comments

Comments
 (0)