openharmony 鸿蒙 js-apis-enterprise-networkManager-sys

2025-06-12 浏览 (1)

@ohos.enterprise.networkManager (Network Management) (System API)

The networkManager module provides APIs for network management of enterprise devices, including obtaining the device IP address and MAC address.

NOTE

The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.

The APIs of this module can be used only in the stage model.

The APIs of this module can be called only by a device administrator application that is enabled.

This topic describes only the system APIs provided by the module. For details about its public APIs, see @ohos.enterprise.networkManager.

Modules to Import

import { networkManager } from '@kit.MDMKit';

networkManager.getAllNetworkInterfaces

getAllNetworkInterfaces(admin: Want, callback: AsyncCallback<Array<string>>): void

Obtains all activated wired network interfaces. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.ENTERPRISE_GET_NETWORK_INFO

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesEnterpriseAdminExtensionAbility.
callbackAsyncCallback<Array<string>>YesCallback invoked to return the result. If the operation is successful, err is null and data is an array of network ports obtained. If the operation fails, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

IDError Message
9200001The application is not an administrator application of the device.
9200002The administrator application does not have permission to manage the device.
201Permission verification failed. The application does not have the permission required to call the API.
202Permission verification failed. A non-system application calls a system API.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

networkManager.getAllNetworkInterfaces(wantTemp, (err, result) => {
  if (err) {
    console.error(`Failed to get all network interfaces. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info(`Succeeded in getting all network interfaces, result : ${JSON.stringify(result)}`);
});

networkManager.getAllNetworkInterfaces

getAllNetworkInterfaces(admin: Want): Promise<Array<string>>

Obtains all activated wired network interfaces. This API uses a promise to return the result.

Required permissions: ohos.permission.ENTERPRISE_GET_NETWORK_INFO

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesEnterpriseAdminExtensionAbility.

Return value

TypeDescription
Promise<Array<string>>Promise used to return the names of all activated wired network interfaces.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

IDError Message
9200001The application is not an administrator application of the device.
9200002The administrator application does not have permission to manage the device.
201Permission verification failed. The application does not have the permission required to call the API.
202Permission verification failed. A non-system application calls a system API.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

networkManager.getAllNetworkInterfaces(wantTemp).then((result) => {
  console.info(`Succeeded in getting all network interfaces, result : ${JSON.stringify(result)}`);
}).catch((err: BusinessError) => {
  console.error(`Failed to get all network interfaces. Code: ${err.code}, message: ${err.message}`);
});

networkManager.getIpAddress

getIpAddress(admin: Want, networkInterface: string, callback: AsyncCallback<string>): void

Obtains the device IP address based on the network interface. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.ENTERPRISE_GET_NETWORK_INFO

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesEnterpriseAdminExtensionAbility.
networkInterfacestringYesNetwork port.
callbackAsyncCallback<string>YesCallback invoked to return the result. If the operation is successful, err is null and data is the IP address obtained. If the operation fails, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

IDError Message
9200001The application is not an administrator application of the device.
9200002The administrator application does not have permission to manage the device.
201Permission verification failed. The application does not have the permission required to call the API.
202Permission verification failed. A non-system application calls a system API.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

networkManager.getIpAddress(wantTemp, 'eth0', (err, result) => {
  if (err) {
    console.error(`Failed to get ip address. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info(`Succeeded in getting ip address, result : ${result}`);
});

networkManager.getIpAddress

getIpAddress(admin: Want, networkInterface: string): Promise<string>

Obtains the device IP address based on the network interface. This API uses a promise to return the result.

Required permissions: ohos.permission.ENTERPRISE_GET_NETWORK_INFO

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesEnterpriseAdminExtensionAbility.
networkInterfacestringYesNetwork port.

Return value

TypeDescription
Promise<string>Promise used to return the device IP address obtained.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

IDError Message
9200001The application is not an administrator application of the device.
9200002The administrator application does not have permission to manage the device.
201Permission verification failed. The application does not have the permission required to call the API.
202Permission verification failed. A non-system application calls a system API.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

networkManager.getIpAddress(wantTemp, 'eth0').then((result) => {
  console.info(`Succeeded in getting ip address, result : ${result}`);
}).catch((err: BusinessError) => {
  console.error(`Failed to get ip address. Code: ${err.code}, message: ${err.message}`);
});

networkManager.getMac

getMac(admin: Want, networkInterface: string, callback: AsyncCallback<string>): void

Obtains the MAC address of a device based on the network interface. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.ENTERPRISE_GET_NETWORK_INFO

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesEnterpriseAdminExtensionAbility.
networkInterfacestringYesNetwork port.
callbackAsyncCallback<string>YesCallback invoked to return the result. If the operation is successful, err is null and data is the MAC address obtained. If the operation fails, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

IDError Message
9200001The application is not an administrator application of the device.
9200002The administrator application does not have permission to manage the device.
201Permission verification failed. The application does not have the permission required to call the API.
202Permission verification failed. A non-system application calls a system API.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

networkManager.getMac(wantTemp, 'eth0', (err, result) => {
  if (err) {
    console.error(`Failed to get mac. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info(`Succeeded in getting mac, result : ${result}`);
});

networkManager.getMac

getMac(admin: Want, networkInterface: string): Promise<string>

Obtains the MAC address of a device based on the network interface. This API uses a promise to return the result.

Required permissions: ohos.permission.ENTERPRISE_GET_NETWORK_INFO

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesEnterpriseAdminExtensionAbility.
networkInterfacestringYesNetwork port.

Return value

TypeDescription
Promise<string>Promise used to return the device MAC address obtained.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

IDError Message
9200001The application is not an administrator application of the device.
9200002The administrator application does not have permission to manage the device.
201Permission verification failed. The application does not have the permission required to call the API.
202Permission verification failed. A non-system application calls a system API.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

networkManager.getMac(wantTemp, 'eth0').then((result) => {
  console.info(`Succeeded in getting mac, result : ${result}`);
}).catch((err: BusinessError) => {
  console.error(`Failed to get mac. Code: ${err.code}, message: ${err.message}`);
});

networkManager.isNetworkInterfaceDisabled

isNetworkInterfaceDisabled(admin: Want, networkInterface: string, callback: AsyncCallback<boolean>): void

Queries whether a specified network interface is disabled. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.ENTERPRISE_GET_NETWORK_INFO

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesEnterpriseAdminExtensionAbility.
networkInterfacestringYesNetwork port.
callbackAsyncCallback<boolean>YesCallback invoked to return the result. If the operation is successful, err is null, and data indicates whether the network port is disabled. The value true means the network port is disabled; and false means the opposite. If the operation fails, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

IDError Message
9200001The application is not an administrator application of the device.
9200002The administrator application does not have permission to manage the device.
201Permission verification failed. The application does not have the permission required to call the API.
202Permission verification failed. A non-system application calls a system API.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

networkManager.isNetworkInterfaceDisabled(wantTemp, 'eth0', (err, result) => {
  if (err) {
    console.error(`Failed to query network interface is disabled or not. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info(`Succeeded in querying network interface is disabled or not, result : ${result}`);
});

networkManager.isNetworkInterfaceDisabled

isNetworkInterfaceDisabled(admin: Want, networkInterface: string): Promise<boolean>

Queries whether a specified network interface is disabled. This API uses a promise to return the result.

Required permissions: ohos.permission.ENTERPRISE_GET_NETWORK_INFO

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesEnterpriseAdminExtensionAbility.
networkInterfacestringYesNetwork port.

Return value

TypeDescription
Promise<boolean>Promise used to return the result. The value true means the network port is disabled, and the value false means the opposite.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

IDError Message
9200001The application is not an administrator application of the device.
9200002The administrator application does not have permission to manage the device.
201Permission verification failed. The application does not have the permission required to call the API.
202Permission verification failed. A non-system application calls a system API.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

networkManager.isNetworkInterfaceDisabled(wantTemp, 'eth0').then((result) => {
  console.info(`Succeeded in querying network interface is disabled or not, result : ${result}`);
}).catch((err: BusinessError) => {
  console.error(`Failed to query network interface is disabled or not. Code: ${err.code}, message: ${err.message}`);
});

networkManager.setNetworkInterfaceDisabled

setNetworkInterfaceDisabled(admin: Want, networkInterface: string, isDisabled: boolean, callback: AsyncCallback<void>): void

Disables a network interface. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.ENTERPRISE_SET_NETWORK

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesEnterpriseAdminExtensionAbility.
networkInterfacestringYesNetwork port.
isDisabledbooleanYesNetwork port status to set. The value true means to disable the network port, and false means to enable the network port.
callbackAsyncCallback<void>YesCallback invoked to return the result. If the operation is successful, err is null. Otherwise, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

IDError Message
9200001The application is not an administrator application of the device.
9200002The administrator application does not have permission to manage the device.
201Permission verification failed. The application does not have the permission required to call the API.
202Permission verification failed. A non-system application calls a system API.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

networkManager.setNetworkInterfaceDisabled(wantTemp, 'eth0', true, (err) => {
  if (err) {
    console.error(`Failed to set network interface disabled. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info(`Succeeded in setting network interface disabled`);
});

networkManager.setNetworkInterfaceDisabled

setNetworkInterfaceDisabled(admin: Want, networkInterface: string, isDisabled: boolean): Promise<void>

Disables a network interface. This API uses a promise to return the result.

Required permissions: ohos.permission.ENTERPRISE_SET_NETWORK

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesEnterpriseAdminExtensionAbility.
networkInterfacestringYesNetwork port.
isDisabledbooleanYesNetwork port status to set. The value true means to disable the network port, and false means to enable the network port.

Return value

TypeDescription
Promise<void>Promise that returns no value. An error object is thrown if the network port fails to be disabled.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

IDError Message
9200001The application is not an administrator application of the device.
9200002The administrator application does not have permission to manage the device.
201Permission verification failed. The application does not have the permission required to call the API.
202Permission verification failed. A non-system application calls a system API.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

networkManager.setNetworkInterfaceDisabled(wantTemp, 'eth0', true).then(() => {
  console.info(`Succeeded in setting network interface disabled`);
}).catch((err: BusinessError) => {
  console.error(`Failed to set network interface disabled. Code: ${err.code}, message: ${err.message}`);
});

networkManager.setGlobalProxy

setGlobalProxy(admin: Want, httpProxy: connection.HttpProxy, callback: AsyncCallback<void>): void

Sets the global network proxy. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.ENTERPRISE_MANAGE_NETWORK

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesEnterpriseAdminExtensionAbility.
httpProxyconnection.HttpProxyYesGlobal HTTP proxy to set.
callbackAsyncCallback<void>YesCallback invoked to return the result. If the operation is successful, err is null. Otherwise, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

IDError Message
9200001The application is not an administrator application of the device.
9200002The administrator application does not have permission to manage the device.
201Permission verification failed. The application does not have the permission required to call the API.
202Permission verification failed. A non-system application calls a system API.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { Want } from '@kit.AbilityKit';
import { connection } from '@kit.NetworkKit';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let exclusionStr: string = "192.168,baidu.com"
let exclusionArray: Array<string> = exclusionStr.split(',');
let httpProxy: connection.HttpProxy = {
  host: "192.168.xx.xxx",
  port: 8080,
  exclusionList: exclusionArray
};

networkManager.setGlobalProxy(wantTemp, httpProxy, (err) => {
  if (err) {
    console.error(`Failed to set network global proxy. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info(`Succeeded in setting network global proxy`);
});

networkManager.setGlobalProxy

setGlobalProxy(admin: Want, httpProxy: connection.HttpProxy): Promise<void>

Sets the global network proxy. This API uses an asynchronous promise to return the result.

Required permissions: ohos.permission.ENTERPRISE_MANAGE_NETWORK

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesEnterpriseAdminExtensionAbility.
httpProxyconnection.HttpProxyYesGlobal HTTP proxy to set.

Return value

TypeDescription
Promise<void>Promise that returns no value. An error object will be thrown if the operation fails.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

IDError Message
9200001The application is not an administrator application of the device.
9200002The administrator application does not have permission to manage the device.
201Permission verification failed. The application does not have the permission required to call the API.
202Permission verification failed. A non-system application calls a system API.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { connection } from '@kit.NetworkKit';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let exclusionStr: string = "192.168,baidu.com"
let exclusionArray: Array<string> = exclusionStr.split(',');
let httpProxy: connection.HttpProxy = {
  host: "192.168.xx.xxx",
  port: 8080,
  exclusionList: exclusionArray
};

networkManager.setGlobalProxy(wantTemp, httpProxy).then(() => {
  console.info(`Succeeded in setting network global proxy`);
}).catch((err: BusinessError) => {
  console.error(`Failed to set network global proxy. Code: ${err.code}, message: ${err.message}`);
});

networkManager.getGlobalProxy

getGlobalProxy(admin: Want, callback: AsyncCallback<connection.HttpProxy>): void

Obtains the global network proxy. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.ENTERPRISE_MANAGE_NETWORK

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesEnterpriseAdminExtensionAbility.
callbackAsyncCallback<connection.HttpProxy>YesCallback invoked to return the result. If the operation is successful, err is null. Otherwise, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

IDError Message
9200001The application is not an administrator application of the device.
9200002The administrator application does not have permission to manage the device.
201Permission verification failed. The application does not have the permission required to call the API.
202Permission verification failed. A non-system application calls a system API.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

networkManager.getGlobalProxy(wantTemp, (err, result) => {
  if (err) {
    console.error(`Failed to get network global proxy. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info(`Succeeded in getting network global proxy, result : ${JSON.stringify(result)}`);
});

networkManager.getGlobalProxy

getGlobalProxy(admin: Want): Promise<connection.HttpProxy>

Obtains the global network proxy. This API uses an asynchronous promise to return the result.

Required permissions: ohos.permission.ENTERPRISE_MANAGE_NETWORK

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesEnterpriseAdminExtensionAbility.

Return value

TypeDescription
Promise<connection.HttpProxy>Promise used to return the global HTTP proxy information obtained.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

IDError Message
9200001The application is not an administrator application of the device.
9200002The administrator application does not have permission to manage the device.
201Permission verification failed. The application does not have the permission required to call the API.
202Permission verification failed. A non-system application calls a system API.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

networkManager.getGlobalProxy(wantTemp).then(() => {
  console.info(`Succeeded in getting network global proxy`);
}).catch((err: BusinessError) => {
  console.error(`Failed to get network global proxy. Code: ${err.code}, message: ${err.message}`);
});

networkManager.addIptablesFilterRule

addIptablesFilterRule(admin: Want, filterRule: AddFilterRule, callback: AsyncCallback<void>): void

Adds a network packet filtering rule for the device. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.ENTERPRISE_MANAGE_NETWORK

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesEnterpriseAdminExtensionAbility.
filterRuleAddFilterRuleYesNetwork packet filtering rule to add.
callbackAsyncCallback<void>YesCallback invoked to return the result. If the operation is successful, err is null. Otherwise, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

IDError Message
9200001The application is not an administrator application of the device.
9200002The administrator application does not have permission to manage the device.
201Permission verification failed. The application does not have the permission required to call the API.
202Permission verification failed. A non-system application calls a system API.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let filterRule: networkManager.AddFilterRule = {
  "ruleNo": 1,
  "srcAddr": "192.168.1.1-192.168.255.255",
  "destAddr": "10.1.1.1",
  "srcPort": "8080",
  "destPort": "8080",
  "uid": "9696",
  "method": networkManager.AddMethod.APPEND,
  "direction": networkManager.Direction.OUTPUT,
  "action": networkManager.Action.DENY,
  "protocol": networkManager.Protocol.UDP,
}

networkManager.addIptablesFilterRule(wantTemp, filterRule, (err) => {
  if (err) {
    console.error(`Failed to set iptables filter rule. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info(`Succeeded in setting iptables filter rule`);
});

networkManager.addIptablesFilterRule

addIptablesFilterRule(admin: Want, filterRule: AddFilterRule): Promise<void>

Adds a network packet filtering rule for the device. This API uses a promise to return the result.

Required permissions: ohos.permission.ENTERPRISE_MANAGE_NETWORK

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesEnterpriseAdminExtensionAbility.
filterRuleAddFilterRuleYesNetwork packet filtering rule to add.

Return value

TypeDescription
Promise<void>Promise that returns no value. If the operation fails, an error object will be thrown.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

IDError Message
9200001The application is not an administrator application of the device.
9200002The administrator application does not have permission to manage the device.
201Permission verification failed. The application does not have the permission required to call the API.
202Permission verification failed. A non-system application calls a system API.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let filterRule: networkManager.AddFilterRule = {
  "ruleNo": 1,
  "srcAddr": "192.168.1.1-192.168.255.255",
  "destAddr": "10.1.1.1",
  "srcPort": "8080",
  "destPort": "8080",
  "uid": "9696",
  "method": networkManager.AddMethod.APPEND,
  "direction": networkManager.Direction.OUTPUT,
  "action": networkManager.Action.DENY,
  "protocol": networkManager.Protocol.UDP,
}

networkManager.addIptablesFilterRule(wantTemp, filterRule).then(() => {
  console.info(`Succeeded in setting iptables filter rule`);
}).catch((err: BusinessError) => {
  console.error(`Failed to set iptables filter rule. Code: ${err.code}, message: ${err.message}`);
});

networkManager.removeIptablesFilterRule

removeIptablesFilterRule(admin: Want, filterRule: RemoveFilterRule, callback: AsyncCallback<void>): void

Network packet filtering rule to remove. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.ENTERPRISE_MANAGE_NETWORK

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesEnterpriseAdminExtensionAbility.
filterRuleRemoveFilterRuleYesNetwork packet filtering rule to remove.
callbackAsyncCallback<void>YesCallback invoked to return the result. If the operation is successful, err is null. Otherwise, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

IDError Message
9200001The application is not an administrator application of the device.
9200002The administrator application does not have permission to manage the device.
201Permission verification failed. The application does not have the permission required to call the API.
202Permission verification failed. A non-system application calls a system API.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let filterRule: networkManager.RemoveFilterRule = {
  "srcAddr": "192.168.1.1-192.168.255.255",
  "destAddr": "10.1.1.1",
  "srcPort": "8080",
  "destPort": "8080",
  "uid": "9696",
  "direction": networkManager.Direction.OUTPUT,
  "action": networkManager.Action.DENY,
  "protocol": networkManager.Protocol.UDP,
}

networkManager.removeIptablesFilterRule(wantTemp, filterRule, (err) => {
  if (err) {
    console.error(`Failed to remove iptables filter rule. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info(`Succeeded in removing iptables filter rule`);
});

networkManager.removeIptablesFilterRule

removeIptablesFilterRule(admin: Want, filterRule: RemoveFilterRule): Promise<void>

Network packet filtering rule to remove. This API uses a promise to return the result.

Required permissions: ohos.permission.ENTERPRISE_MANAGE_NETWORK

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesEnterpriseAdminExtensionAbility.
filterRuleRemoveFilterRuleYesNetwork packet filtering rule to remove.

Return value

TypeDescription
Promise<void>Promise that returns no value. If the operation fails, an error object will be thrown.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

IDError Message
9200001The application is not an administrator application of the device.
9200002The administrator application does not have permission to manage the device.
201Permission verification failed. The application does not have the permission required to call the API.
202Permission verification failed. A non-system application calls a system API.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let filterRule: networkManager.RemoveFilterRule = {
  "srcAddr": "192.168.1.1-192.168.255.255",
  "destAddr": "10.1.1.1",
  "srcPort": "8080",
  "destPort": "8080",
  "uid": "9696",
  "direction": networkManager.Direction.OUTPUT,
  "action": networkManager.Action.DENY,
  "protocol": networkManager.Protocol.UDP,
}

networkManager.removeIptablesFilterRule(wantTemp, filterRule).then(() => {
  console.info(`Succeeded in removing iptables filter rule`);
}).catch((err: BusinessError) => {
  console.error(`Failed to remove iptables filter rule. Code: ${err.code}, message: ${err.message}`);
});

networkManager.listIptablesFilterRules

listIptablesFilterRules(admin: Want, callback: AsyncCallback<string>): void

Obtains network packet filtering rules. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.ENTERPRISE_MANAGE_NETWORK

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesEnterpriseAdminExtensionAbility.
callbackAsyncCallback<string>YesCallback invoked to return the result. If the operation is successful, err is null. Otherwise, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

IDError Message
9200001The application is not an administrator application of the device.
9200002The administrator application does not have permission to manage the device.
201Permission verification failed. The application does not have the permission required to call the API.
202Permission verification failed. A non-system application calls a system API.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

networkManager.listIptablesFilterRules(wantTemp, (err, result) => {
  if (err) {
    console.error(`Failed to get iptables filter rule. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info(`Succeeded in getting iptables filter rule, result : ${result}`);
});

networkManager.listIptablesFilterRules

listIptablesFilterRules(admin: Want): Promise<string>

Obtains network packet filtering rules. This API uses a promise to return the result.

Required permissions: ohos.permission.ENTERPRISE_MANAGE_NETWORK

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesEnterpriseAdminExtensionAbility.

Return value

TypeDescription
Promise<string>Promise used to return the network packet filtering rules obtained.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

IDError Message
9200001The application is not an administrator application of the device.
9200002The administrator application does not have permission to manage the device.
201Permission verification failed. The application does not have the permission required to call the API.
202Permission verification failed. A non-system application calls a system API.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

networkManager.listIptablesFilterRules(wantTemp).then((result) => {
  console.info(`Succeeded in getting iptables filter rule, result: ${result}`);
}).catch((err: BusinessError) => {
  console.error(`Failed to remove iptables filter rule. Code: ${err.code}, message: ${err.message}`);
});

AddFilterRule

Network packet filtering rule to add.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

NameTypeMandatoryDescription
ruleNonumberNoSequence number of the rule.
srcAddrstringNoSource IP address.
destAddrstringNoDestination IP address.
srcPortstringNoPort of the source IP address.
destPortstringNoPort of the destination IP address.
uidstringNoUID of the application.
methodAddMethodYesMethod used to add the data packets.
directionDirectionYesDirection chains to which the rule applies.
actionActionYesAction to take, that is, receive or discard the data packets.
protocolProtocolNoNetwork protocol.

RemoveFilterRule

Network packet filtering rule to remove.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

NameTypeMandatoryDescription
srcAddrstringNoSource IP address.
destAddrstringNoDestination IP address.
srcPortstringNoPort of the source IP address.
destPortstringNoPort of the destination IP address.
uidstringNoUID of the application.
directionDirectionYesDirection chains to which the rule applies.
actionActionNoAction to take, that is, receive or discard the data packets.
protocolProtocolNoNetwork protocol.

AddMethod

Enumerates the methods used to add the network packets.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

NameValueDescription
APPEND0Append the packet.
INSERT1Insert the packet.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙MDM Kit

harmony 鸿蒙Enterprise Device Management Error Codes

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

harmony 鸿蒙@ohos.enterprise.accountManager (Account Management) (System API)

harmony 鸿蒙@ohos.enterprise.accountManager (Account Management)

harmony 鸿蒙@ohos.enterprise.adminManager (Enterprise Device Management) (System API)

harmony 鸿蒙@ohos.enterprise.adminManager (Enterprise Device Management)

harmony 鸿蒙@ohos.enterprise.applicationManager (Application Management (System API)

harmony 鸿蒙@ohos.enterprise.applicationManager (Application Management)

harmony 鸿蒙@ohos.enterprise.bluetoothManager (Bluetooth Management) (System API)

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/ALFkLq