Network
Network management API allows you to manually set network interfaces or set back DHCP and current active network info.
All methods
Method | Description | Supported since |
---|---|---|
getActiveInfo() | Information about network interfaces, IP addesses and MAC addresses (DEPRECATED) | 4.0 |
listInterfaces() | Information about network interfaces | 4.9 |
setManual() | Allows you to set network settings manually | 4.0 |
setDHCP() | Allows you to set network settings automatically from DHCP | 4.0 |
disableInterface() | Disables a network interface | 4.13 |
getActiveInfo()
Method getActiveInfo()
will display information about connected network.
This method is deprecated. Use listInterfaces()
instead.
Javascript example
await sos.management.network.getActiveInfo();
Example of response
{
"activeInterface": "ethernet",
"dns": [
"192.168.1.1",
"1.1.1.1"
],
"gateway": "192.168.1.1",
"localAddress": "192.168.1.137",
"ethernetMacAddress": "b8:27:eb:25:8f:63",
"wifiMacAddress": "b8:27:eb:25:8f:63",
"netmask": "255.255.255.0"
}
Wifi connection strength is described as percentage in range from 0 to 100, linearly converted from dBm -90 to -30 respectively based on platform.
{
"activeInterface": "wifi",
"dns": [
"192.168.1.1",
"1.1.1.1"
],
"gateway": "192.168.1.1",
"localAddress": "192.168.1.137",
"ethernetMacAddress": "b8:27:eb:25:8f:63",
"wifiMacAddress": "b8:27:eb:25:8f:63",
"netmask": "255.255.255.0",
"wifiSsid": "hotel",
"wifiStrength": "87"
}
listInterfaces()
Returns list of all network interfaces, and their information like MAC address, IP address, etc.
Javascript example
const interfaces = await sos.management.network.listInterfaces();
Example of response
Wifi connection strength is described as percentage in range from 0 to 100, linearly converted from dBm -90 to -30 respectively based on platform.
[
{
"type": "ethernet",
"name": "eth0",
"macAddress": "b8:27:eb:25:8f:63",
"localAddress": "192.168.1.137",
"gateway": "192.168.1.1",
"netmask": "255.255.255.0",
"dns": [
"192.168.1.1",
"1.1.1.1"
]
},
{
"type": "wifi",
"name": "wlan0",
"macAddress": "b8:27:eb:25:8f:63",
"localAddress": "192.168.1.138",
"gateway": "192.168.1.1",
"netmask": "255.255.255.0",
"dns": [
"192.168.1.1",
"1.1.1.1"
],
"wifiSsid": "hotel",
"wifiStrength": "87"
}
]
setManual()
Manually configures a network interface. If the interface is disabled, it will be enabled.
Wi-Fi interface can be configured with this method but it has to be first enabled via the Wi-Fi API.
Object properties
New way
Name | Type | Required | Description |
---|---|---|---|
interfaceName | String | Yes | Network interface name, can be retrieved from listInterfaces() |
options.localAddress | String | Yes | Network local address |
options.gateway | String | Yes | Network gateway |
options.netmask | String | Yes | Network netmask |
options.dns | Array | Yes | Array of additionally DNSs |
Old way (deprecated)
Name | Type | Required | Description |
---|---|---|---|
interface | String | Yes | Network type interface, can be only ethernet or wifi |
localAddress | String | Yes | Network local address |
gateway | String | Yes | Network gateway |
netmask | String | Yes | Network netmask |
dns | Array | Yes | Array of additionally DNSs |
Javascript example
// new way
await sos.management.network.setManual('eth0', {
localAddress: '192.168.1.133',
gateway: '192.168.1.1',
netmask: '255.255.255.0',
dns: ['8.8.8.8', '192.168.1.1'],
});
// old way (deprecated)
await sos.management.network.setManual({
interface: 'ethernet',
localAddress: '192.168.1.133',
gateway: '192.168.1.1',
netmask: '255.255.255.0',
dns: ['8.8.8.8', '192.168.1.1'],
});
setDHCP()
Configures a network interface to use DHCP to get an IP address asigned from the network. If the interface is disabled, it will be enabled.
Wi-Fi interface can be configured with this method but it has to be first enabled via the Wi-Fi API.
Object properties
New way
Name | Type | Required | Description |
---|---|---|---|
interfaceName | String | Yes | Network interface name, can be retrieved from listInterfaces() |
Old way (deprecated)
Name | Type | Required | Description |
---|---|---|---|
networkInterface | String | Yes | Network type interface, can be only ethernet or wifi |
Javascript example
// new way
await sos.management.network.setDHCP('eth0');
// old way (deprecated)
await sos.management.network.setDHCP('ethernet');
disableInterface()
Disables a network interface
Param | Type | Required | Description |
---|---|---|---|
interfaceName | String | Yes | Name of the network interface, that will be disabled |
Javascript example
await sos.management.wifi.disableInterface("eth0");
A disabled network interface can be re-enabled simply by calling either setDHCP()
or setManual()
.
Don't use this method to disable Wi-Fi. Use Wi-Fi API to enable/disable Wi-Fi.