1e41f4b71Sopenharmony_ci# @ohos.enterprise.networkManager (Network Management) (System API) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **networkManager** module provides APIs for network management of enterprise devices, including obtaining the device IP address and MAC address. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> 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. 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci> The APIs of this module can be used only in the stage model. 10e41f4b71Sopenharmony_ci> 11e41f4b71Sopenharmony_ci> The APIs of this module can be called only by a [device administrator application](../../mdm/mdm-kit-guide.md#introduction) that is [enabled](js-apis-enterprise-adminManager-sys.md#adminmanagerenableadmin). 12e41f4b71Sopenharmony_ci> 13e41f4b71Sopenharmony_ci> This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.enterprise.networkManager](js-apis-enterprise-networkManager.md). 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci## Modules to Import 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci```ts 18e41f4b71Sopenharmony_ciimport { networkManager } from '@kit.MDMKit'; 19e41f4b71Sopenharmony_ci``` 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci## networkManager.getAllNetworkInterfaces 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_cigetAllNetworkInterfaces(admin: Want, callback: AsyncCallback<Array<string>>): void 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ciObtains all activated network ports through the specified device administrator application. This API uses an asynchronous callback to return the result. 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_GET_NETWORK_INFO 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci**Parameters** 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 35e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------------------------- | 36e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 37e41f4b71Sopenharmony_ci| callback | AsyncCallback<Array<string>> | Yes | Callback used 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. | 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci**Error codes** 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci| ID| Error Message | 44e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 45e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 46e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 47e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 48e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 49e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci**Example** 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci```ts 54e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 55e41f4b71Sopenharmony_cilet wantTemp: Want = { 56e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 57e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 58e41f4b71Sopenharmony_ci}; 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_cinetworkManager.getAllNetworkInterfaces(wantTemp, (err, result) => { 61e41f4b71Sopenharmony_ci if (err) { 62e41f4b71Sopenharmony_ci console.error(`Failed to get all network interfaces. Code: ${err.code}, message: ${err.message}`); 63e41f4b71Sopenharmony_ci return; 64e41f4b71Sopenharmony_ci } 65e41f4b71Sopenharmony_ci console.info(`Succeeded in getting all network interfaces, result : ${JSON.stringify(result)}`); 66e41f4b71Sopenharmony_ci}); 67e41f4b71Sopenharmony_ci``` 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ci## networkManager.getAllNetworkInterfaces 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_cigetAllNetworkInterfaces(admin: Want): Promise<Array<string>> 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ciObtains all activated network ports through the specified device administrator application. This API uses a promise to return the result. 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_GET_NETWORK_INFO 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci**Parameters** 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 83e41f4b71Sopenharmony_ci| ----- | ----------------------------------- | ---- | ------- | 84e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci**Return value** 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ci| Type | Description | 89e41f4b71Sopenharmony_ci| --------------------- | ------------------------- | 90e41f4b71Sopenharmony_ci| Promise<Array<string>> | Promise used to return an array of network ports obtained. | 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci**Error codes** 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ci| ID| Error Message | 97e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 98e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 99e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 100e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 101e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 102e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci**Example** 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_ci```ts 107e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 108e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 109e41f4b71Sopenharmony_cilet wantTemp: Want = { 110e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 111e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 112e41f4b71Sopenharmony_ci}; 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_cinetworkManager.getAllNetworkInterfaces(wantTemp).then((result) => { 115e41f4b71Sopenharmony_ci console.info(`Succeeded in getting all network interfaces, result : ${JSON.stringify(result)}`); 116e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 117e41f4b71Sopenharmony_ci console.error(`Failed to get all network interfaces. Code: ${err.code}, message: ${err.message}`); 118e41f4b71Sopenharmony_ci}); 119e41f4b71Sopenharmony_ci``` 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci## networkManager.getIpAddress 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_cigetIpAddress(admin: Want, networkInterface: string, callback: AsyncCallback<string>): void 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_ciObtains the device IP address based on the network port through the specified device administrator application. This API uses an asynchronous callback to return the result. 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_GET_NETWORK_INFO 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci**Parameters** 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 135e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------------------------- | 136e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 137e41f4b71Sopenharmony_ci| networkInterface | string | Yes | Network port. | 138e41f4b71Sopenharmony_ci| callback | AsyncCallback<string> | Yes | Callback used 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. | 139e41f4b71Sopenharmony_ci 140e41f4b71Sopenharmony_ci**Error codes** 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci| ID| Error Message | 145e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 146e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 147e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 148e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 149e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 150e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ci**Example** 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ci```ts 155e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 156e41f4b71Sopenharmony_cilet wantTemp: Want = { 157e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 158e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 159e41f4b71Sopenharmony_ci}; 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_cinetworkManager.getIpAddress(wantTemp, 'eth0', (err, result) => { 162e41f4b71Sopenharmony_ci if (err) { 163e41f4b71Sopenharmony_ci console.error(`Failed to get ip address. Code: ${err.code}, message: ${err.message}`); 164e41f4b71Sopenharmony_ci return; 165e41f4b71Sopenharmony_ci } 166e41f4b71Sopenharmony_ci console.info(`Succeeded in getting ip address, result : ${result}`); 167e41f4b71Sopenharmony_ci}); 168e41f4b71Sopenharmony_ci``` 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_ci## networkManager.getIpAddress 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_cigetIpAddress(admin: Want, networkInterface: string): Promise<string> 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ciObtains the device IP address based on the network port through the specified device administrator application. This API uses a promise to return the result. 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_GET_NETWORK_INFO 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci 181e41f4b71Sopenharmony_ci**Parameters** 182e41f4b71Sopenharmony_ci 183e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 184e41f4b71Sopenharmony_ci| ----- | ----------------------------------- | ---- | ------- | 185e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 186e41f4b71Sopenharmony_ci| networkInterface | string | Yes | Network port. | 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ci**Return value** 189e41f4b71Sopenharmony_ci 190e41f4b71Sopenharmony_ci| Type | Description | 191e41f4b71Sopenharmony_ci| --------------------- | ------------------------- | 192e41f4b71Sopenharmony_ci| Promise<string> | Promise used to return the device IP address obtained. | 193e41f4b71Sopenharmony_ci 194e41f4b71Sopenharmony_ci**Error codes** 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ci| ID| Error Message | 199e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 200e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 201e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 202e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 203e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 204e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 205e41f4b71Sopenharmony_ci 206e41f4b71Sopenharmony_ci**Example** 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_ci```ts 209e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 210e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 211e41f4b71Sopenharmony_cilet wantTemp: Want = { 212e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 213e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 214e41f4b71Sopenharmony_ci}; 215e41f4b71Sopenharmony_ci 216e41f4b71Sopenharmony_cinetworkManager.getIpAddress(wantTemp, 'eth0').then((result) => { 217e41f4b71Sopenharmony_ci console.info(`Succeeded in getting ip address, result : ${result}`); 218e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 219e41f4b71Sopenharmony_ci console.error(`Failed to get ip address. Code: ${err.code}, message: ${err.message}`); 220e41f4b71Sopenharmony_ci}); 221e41f4b71Sopenharmony_ci``` 222e41f4b71Sopenharmony_ci 223e41f4b71Sopenharmony_ci## networkManager.getMac 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_cigetMac(admin: Want, networkInterface: string, callback: AsyncCallback<string>): void 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ciObtains the device MAC address based on the network port through the specified device administrator application. This API uses an asynchronous callback to return the result. 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_GET_NETWORK_INFO 230e41f4b71Sopenharmony_ci 231e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_ci 234e41f4b71Sopenharmony_ci**Parameters** 235e41f4b71Sopenharmony_ci 236e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 237e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------------------------- | 238e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 239e41f4b71Sopenharmony_ci| networkInterface | string | Yes | Network port. | 240e41f4b71Sopenharmony_ci| callback | AsyncCallback<string> | Yes | Callback used 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. | 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ci**Error codes** 243e41f4b71Sopenharmony_ci 244e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 245e41f4b71Sopenharmony_ci 246e41f4b71Sopenharmony_ci| ID| Error Message | 247e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 248e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 249e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 250e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 251e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 252e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 253e41f4b71Sopenharmony_ci 254e41f4b71Sopenharmony_ci**Example** 255e41f4b71Sopenharmony_ci 256e41f4b71Sopenharmony_ci```ts 257e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 258e41f4b71Sopenharmony_cilet wantTemp: Want = { 259e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 260e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 261e41f4b71Sopenharmony_ci}; 262e41f4b71Sopenharmony_ci 263e41f4b71Sopenharmony_cinetworkManager.getMac(wantTemp, 'eth0', (err, result) => { 264e41f4b71Sopenharmony_ci if (err) { 265e41f4b71Sopenharmony_ci console.error(`Failed to get mac. Code: ${err.code}, message: ${err.message}`); 266e41f4b71Sopenharmony_ci return; 267e41f4b71Sopenharmony_ci } 268e41f4b71Sopenharmony_ci console.info(`Succeeded in getting mac, result : ${result}`); 269e41f4b71Sopenharmony_ci}); 270e41f4b71Sopenharmony_ci``` 271e41f4b71Sopenharmony_ci 272e41f4b71Sopenharmony_ci## networkManager.getMac 273e41f4b71Sopenharmony_ci 274e41f4b71Sopenharmony_cigetMac(admin: Want, networkInterface: string): Promise\<string> 275e41f4b71Sopenharmony_ci 276e41f4b71Sopenharmony_ciObtains the device MAC address based on the network port through the specified device administrator application. This API uses a promise to return the result. 277e41f4b71Sopenharmony_ci 278e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_GET_NETWORK_INFO 279e41f4b71Sopenharmony_ci 280e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 281e41f4b71Sopenharmony_ci 282e41f4b71Sopenharmony_ci 283e41f4b71Sopenharmony_ci**Parameters** 284e41f4b71Sopenharmony_ci 285e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 286e41f4b71Sopenharmony_ci| ----- | ----------------------------------- | ---- | ------- | 287e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 288e41f4b71Sopenharmony_ci| networkInterface | string | Yes | Network port. | 289e41f4b71Sopenharmony_ci 290e41f4b71Sopenharmony_ci**Return value** 291e41f4b71Sopenharmony_ci 292e41f4b71Sopenharmony_ci| Type | Description | 293e41f4b71Sopenharmony_ci| --------------------- | ------------------------- | 294e41f4b71Sopenharmony_ci| Promise<string> | Promise used to return the device MAC address obtained. | 295e41f4b71Sopenharmony_ci 296e41f4b71Sopenharmony_ci**Error codes** 297e41f4b71Sopenharmony_ci 298e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 299e41f4b71Sopenharmony_ci 300e41f4b71Sopenharmony_ci| ID| Error Message | 301e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 302e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 303e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 304e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 305e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 306e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 307e41f4b71Sopenharmony_ci 308e41f4b71Sopenharmony_ci**Example** 309e41f4b71Sopenharmony_ci 310e41f4b71Sopenharmony_ci```ts 311e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 312e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 313e41f4b71Sopenharmony_cilet wantTemp: Want = { 314e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 315e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 316e41f4b71Sopenharmony_ci}; 317e41f4b71Sopenharmony_ci 318e41f4b71Sopenharmony_cinetworkManager.getMac(wantTemp, 'eth0').then((result) => { 319e41f4b71Sopenharmony_ci console.info(`Succeeded in getting mac, result : ${result}`); 320e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 321e41f4b71Sopenharmony_ci console.error(`Failed to get mac. Code: ${err.code}, message: ${err.message}`); 322e41f4b71Sopenharmony_ci}); 323e41f4b71Sopenharmony_ci``` 324e41f4b71Sopenharmony_ci 325e41f4b71Sopenharmony_ci## networkManager.isNetworkInterfaceDisabled 326e41f4b71Sopenharmony_ci 327e41f4b71Sopenharmony_ciisNetworkInterfaceDisabled(admin: Want, networkInterface: string, callback: AsyncCallback<boolean>): void 328e41f4b71Sopenharmony_ci 329e41f4b71Sopenharmony_ciChecks whether a network port is disabled through the specified device administrator application. This API uses an asynchronous callback to return the result. 330e41f4b71Sopenharmony_ci 331e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_GET_NETWORK_INFO 332e41f4b71Sopenharmony_ci 333e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 334e41f4b71Sopenharmony_ci 335e41f4b71Sopenharmony_ci 336e41f4b71Sopenharmony_ci**Parameters** 337e41f4b71Sopenharmony_ci 338e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 339e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------------------------- | 340e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 341e41f4b71Sopenharmony_ci| networkInterface | string | Yes | Network port. | 342e41f4b71Sopenharmony_ci| callback | AsyncCallback<boolean> | Yes | Callback used 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. | 343e41f4b71Sopenharmony_ci 344e41f4b71Sopenharmony_ci**Error codes** 345e41f4b71Sopenharmony_ci 346e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 347e41f4b71Sopenharmony_ci 348e41f4b71Sopenharmony_ci| ID| Error Message | 349e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 350e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 351e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 352e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 353e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 354e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 355e41f4b71Sopenharmony_ci 356e41f4b71Sopenharmony_ci**Example** 357e41f4b71Sopenharmony_ci 358e41f4b71Sopenharmony_ci```ts 359e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 360e41f4b71Sopenharmony_cilet wantTemp: Want = { 361e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 362e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 363e41f4b71Sopenharmony_ci}; 364e41f4b71Sopenharmony_ci 365e41f4b71Sopenharmony_cinetworkManager.isNetworkInterfaceDisabled(wantTemp, 'eth0', (err, result) => { 366e41f4b71Sopenharmony_ci if (err) { 367e41f4b71Sopenharmony_ci console.error(`Failed to query network interface is disabled or not. Code: ${err.code}, message: ${err.message}`); 368e41f4b71Sopenharmony_ci return; 369e41f4b71Sopenharmony_ci } 370e41f4b71Sopenharmony_ci console.info(`Succeeded in querying network interface is disabled or not, result : ${result}`); 371e41f4b71Sopenharmony_ci}); 372e41f4b71Sopenharmony_ci``` 373e41f4b71Sopenharmony_ci 374e41f4b71Sopenharmony_ci## networkManager.isNetworkInterfaceDisabled 375e41f4b71Sopenharmony_ci 376e41f4b71Sopenharmony_ciisNetworkInterfaceDisabled(admin: Want, networkInterface: string): Promise<boolean> 377e41f4b71Sopenharmony_ci 378e41f4b71Sopenharmony_ciChecks whether a network port is disabled through the specified device administrator application. This API uses a promise to return the result. 379e41f4b71Sopenharmony_ci 380e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_GET_NETWORK_INFO 381e41f4b71Sopenharmony_ci 382e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 383e41f4b71Sopenharmony_ci 384e41f4b71Sopenharmony_ci 385e41f4b71Sopenharmony_ci**Parameters** 386e41f4b71Sopenharmony_ci 387e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 388e41f4b71Sopenharmony_ci| ----- | ----------------------------------- | ---- | ------- | 389e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 390e41f4b71Sopenharmony_ci| networkInterface | string | Yes | Network port. | 391e41f4b71Sopenharmony_ci 392e41f4b71Sopenharmony_ci**Return value** 393e41f4b71Sopenharmony_ci 394e41f4b71Sopenharmony_ci| Type | Description | 395e41f4b71Sopenharmony_ci| --------------------- | ------------------------- | 396e41f4b71Sopenharmony_ci| Promise<boolean> | Promise used to return the result. The value **true** means the network port is disabled, and the value **false** means the opposite. | 397e41f4b71Sopenharmony_ci 398e41f4b71Sopenharmony_ci**Error codes** 399e41f4b71Sopenharmony_ci 400e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 401e41f4b71Sopenharmony_ci 402e41f4b71Sopenharmony_ci| ID| Error Message | 403e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 404e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 405e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 406e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 407e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 408e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 409e41f4b71Sopenharmony_ci 410e41f4b71Sopenharmony_ci**Example** 411e41f4b71Sopenharmony_ci 412e41f4b71Sopenharmony_ci```ts 413e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 414e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 415e41f4b71Sopenharmony_cilet wantTemp: Want = { 416e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 417e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 418e41f4b71Sopenharmony_ci}; 419e41f4b71Sopenharmony_ci 420e41f4b71Sopenharmony_cinetworkManager.isNetworkInterfaceDisabled(wantTemp, 'eth0').then((result) => { 421e41f4b71Sopenharmony_ci console.info(`Succeeded in querying network interface is disabled or not, result : ${result}`); 422e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 423e41f4b71Sopenharmony_ci console.error(`Failed to query network interface is disabled or not. Code: ${err.code}, message: ${err.message}`); 424e41f4b71Sopenharmony_ci}); 425e41f4b71Sopenharmony_ci``` 426e41f4b71Sopenharmony_ci 427e41f4b71Sopenharmony_ci## networkManager.setNetworkInterfaceDisabled 428e41f4b71Sopenharmony_ci 429e41f4b71Sopenharmony_cisetNetworkInterfaceDisabled(admin: Want, networkInterface: string, isDisabled: boolean, callback: AsyncCallback<void>): void 430e41f4b71Sopenharmony_ci 431e41f4b71Sopenharmony_ciDisables a network port through the specified device administrator application. This API uses an asynchronous callback to return the result. 432e41f4b71Sopenharmony_ci 433e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_SET_NETWORK 434e41f4b71Sopenharmony_ci 435e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 436e41f4b71Sopenharmony_ci 437e41f4b71Sopenharmony_ci 438e41f4b71Sopenharmony_ci**Parameters** 439e41f4b71Sopenharmony_ci 440e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 441e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------------------------- | 442e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 443e41f4b71Sopenharmony_ci| networkInterface | string | Yes | Network port. | 444e41f4b71Sopenharmony_ci| isDisabled | boolean | Yes | Network port status to set. The value **true** means to disable the network port, and **false** means to enable the network port. | 445e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 446e41f4b71Sopenharmony_ci 447e41f4b71Sopenharmony_ci**Error codes** 448e41f4b71Sopenharmony_ci 449e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 450e41f4b71Sopenharmony_ci 451e41f4b71Sopenharmony_ci| ID| Error Message | 452e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 453e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 454e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 455e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 456e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 457e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 458e41f4b71Sopenharmony_ci 459e41f4b71Sopenharmony_ci**Example** 460e41f4b71Sopenharmony_ci 461e41f4b71Sopenharmony_ci```ts 462e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 463e41f4b71Sopenharmony_cilet wantTemp: Want = { 464e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 465e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 466e41f4b71Sopenharmony_ci}; 467e41f4b71Sopenharmony_ci 468e41f4b71Sopenharmony_cinetworkManager.setNetworkInterfaceDisabled(wantTemp, 'eth0', true, (err) => { 469e41f4b71Sopenharmony_ci if (err) { 470e41f4b71Sopenharmony_ci console.error(`Failed to set network interface disabled. Code: ${err.code}, message: ${err.message}`); 471e41f4b71Sopenharmony_ci return; 472e41f4b71Sopenharmony_ci } 473e41f4b71Sopenharmony_ci console.info(`Succeeded in setting network interface disabled`); 474e41f4b71Sopenharmony_ci}); 475e41f4b71Sopenharmony_ci``` 476e41f4b71Sopenharmony_ci 477e41f4b71Sopenharmony_ci## networkManager.setNetworkInterfaceDisabled 478e41f4b71Sopenharmony_ci 479e41f4b71Sopenharmony_cisetNetworkInterfaceDisabled(admin: Want, networkInterface: string, isDisabled: boolean): Promise<void> 480e41f4b71Sopenharmony_ci 481e41f4b71Sopenharmony_ciDisables a network port through the specified device administrator application. This API uses a promise to return the result. 482e41f4b71Sopenharmony_ci 483e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_SET_NETWORK 484e41f4b71Sopenharmony_ci 485e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 486e41f4b71Sopenharmony_ci 487e41f4b71Sopenharmony_ci 488e41f4b71Sopenharmony_ci**Parameters** 489e41f4b71Sopenharmony_ci 490e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 491e41f4b71Sopenharmony_ci| ----- | ----------------------------------- | ---- | ------- | 492e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 493e41f4b71Sopenharmony_ci| networkInterface | string | Yes | Network port. | 494e41f4b71Sopenharmony_ci| isDisabled | boolean | Yes | Network port status to set. The value **true** means to disable the network port, and **false** means to enable the network port. | 495e41f4b71Sopenharmony_ci 496e41f4b71Sopenharmony_ci**Return value** 497e41f4b71Sopenharmony_ci 498e41f4b71Sopenharmony_ci| Type | Description | 499e41f4b71Sopenharmony_ci| --------------------- | ------------------------- | 500e41f4b71Sopenharmony_ci| Promise<void> | Promise that returns no value. An error object is thrown if the network port fails to be disabled. | 501e41f4b71Sopenharmony_ci 502e41f4b71Sopenharmony_ci**Error codes** 503e41f4b71Sopenharmony_ci 504e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 505e41f4b71Sopenharmony_ci 506e41f4b71Sopenharmony_ci| ID| Error Message | 507e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 508e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 509e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 510e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 511e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 512e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 513e41f4b71Sopenharmony_ci 514e41f4b71Sopenharmony_ci**Example** 515e41f4b71Sopenharmony_ci 516e41f4b71Sopenharmony_ci```ts 517e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 518e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 519e41f4b71Sopenharmony_cilet wantTemp: Want = { 520e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 521e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 522e41f4b71Sopenharmony_ci}; 523e41f4b71Sopenharmony_ci 524e41f4b71Sopenharmony_cinetworkManager.setNetworkInterfaceDisabled(wantTemp, 'eth0', true).then(() => { 525e41f4b71Sopenharmony_ci console.info(`Succeeded in setting network interface disabled`); 526e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 527e41f4b71Sopenharmony_ci console.error(`Failed to set network interface disabled. Code: ${err.code}, message: ${err.message}`); 528e41f4b71Sopenharmony_ci}); 529e41f4b71Sopenharmony_ci``` 530e41f4b71Sopenharmony_ci 531e41f4b71Sopenharmony_ci## networkManager.setGlobalProxy 532e41f4b71Sopenharmony_ci 533e41f4b71Sopenharmony_cisetGlobalProxy(admin: Want, httpProxy: connection.HttpProxy, callback: AsyncCallback\<void>): void 534e41f4b71Sopenharmony_ci 535e41f4b71Sopenharmony_ciSets the global network proxy through the specified device administrator application. This API uses an asynchronous callback to return the result. 536e41f4b71Sopenharmony_ci 537e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 538e41f4b71Sopenharmony_ci 539e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 540e41f4b71Sopenharmony_ci 541e41f4b71Sopenharmony_ci 542e41f4b71Sopenharmony_ci**Parameters** 543e41f4b71Sopenharmony_ci 544e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 545e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------------------------- | 546e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 547e41f4b71Sopenharmony_ci| httpProxy | [connection.HttpProxy](../apis-network-kit/js-apis-net-connection.md#httpproxy10) | Yes | Global HTTP proxy to set. | 548e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 549e41f4b71Sopenharmony_ci 550e41f4b71Sopenharmony_ci**Error codes** 551e41f4b71Sopenharmony_ci 552e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 553e41f4b71Sopenharmony_ci 554e41f4b71Sopenharmony_ci| ID| Error Message | 555e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 556e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 557e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 558e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 559e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 560e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 561e41f4b71Sopenharmony_ci 562e41f4b71Sopenharmony_ci**Example** 563e41f4b71Sopenharmony_ci 564e41f4b71Sopenharmony_ci```ts 565e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 566e41f4b71Sopenharmony_ciimport { connection } from '@kit.NetworkKit'; 567e41f4b71Sopenharmony_cilet wantTemp: Want = { 568e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 569e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 570e41f4b71Sopenharmony_ci}; 571e41f4b71Sopenharmony_cilet exclusionStr: string = "192.168,baidu.com" 572e41f4b71Sopenharmony_cilet exclusionArray: Array<string> = exclusionStr.split(','); 573e41f4b71Sopenharmony_cilet httpProxy: connection.HttpProxy = { 574e41f4b71Sopenharmony_ci host: "192.168.xx.xxx", 575e41f4b71Sopenharmony_ci port: 8080, 576e41f4b71Sopenharmony_ci exclusionList: exclusionArray 577e41f4b71Sopenharmony_ci}; 578e41f4b71Sopenharmony_ci 579e41f4b71Sopenharmony_cinetworkManager.setGlobalProxy(wantTemp, httpProxy, (err) => { 580e41f4b71Sopenharmony_ci if (err) { 581e41f4b71Sopenharmony_ci console.error(`Failed to set network global proxy. Code: ${err.code}, message: ${err.message}`); 582e41f4b71Sopenharmony_ci return; 583e41f4b71Sopenharmony_ci } 584e41f4b71Sopenharmony_ci console.info(`Succeeded in setting network global proxy`); 585e41f4b71Sopenharmony_ci}); 586e41f4b71Sopenharmony_ci``` 587e41f4b71Sopenharmony_ci 588e41f4b71Sopenharmony_ci## networkManager.setGlobalProxy 589e41f4b71Sopenharmony_ci 590e41f4b71Sopenharmony_cisetGlobalProxy(admin: Want, httpProxy: connection.HttpProxy): Promise\<void> 591e41f4b71Sopenharmony_ci 592e41f4b71Sopenharmony_ciSets the global network proxy through the specified device administrator application. This API uses a promise to return the result. 593e41f4b71Sopenharmony_ci 594e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 595e41f4b71Sopenharmony_ci 596e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 597e41f4b71Sopenharmony_ci 598e41f4b71Sopenharmony_ci 599e41f4b71Sopenharmony_ci**Parameters** 600e41f4b71Sopenharmony_ci 601e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 602e41f4b71Sopenharmony_ci| ----- | ----------------------------------- | ---- | ------- | 603e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 604e41f4b71Sopenharmony_ci| httpProxy | [connection.HttpProxy](../apis-network-kit/js-apis-net-connection.md#httpproxy10) | Yes | Global HTTP proxy to set. | 605e41f4b71Sopenharmony_ci 606e41f4b71Sopenharmony_ci**Return value** 607e41f4b71Sopenharmony_ci 608e41f4b71Sopenharmony_ci| Type | Description | 609e41f4b71Sopenharmony_ci| --------------------- | ------------------------- | 610e41f4b71Sopenharmony_ci| Promise<void> | Promise that returns no value. An error object will be thrown if the operation fails. | 611e41f4b71Sopenharmony_ci 612e41f4b71Sopenharmony_ci**Error codes** 613e41f4b71Sopenharmony_ci 614e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 615e41f4b71Sopenharmony_ci 616e41f4b71Sopenharmony_ci| ID| Error Message | 617e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 618e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 619e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 620e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 621e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 622e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 623e41f4b71Sopenharmony_ci 624e41f4b71Sopenharmony_ci**Example** 625e41f4b71Sopenharmony_ci 626e41f4b71Sopenharmony_ci```ts 627e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 628e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 629e41f4b71Sopenharmony_ciimport { connection } from '@kit.NetworkKit'; 630e41f4b71Sopenharmony_cilet wantTemp: Want = { 631e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 632e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 633e41f4b71Sopenharmony_ci}; 634e41f4b71Sopenharmony_cilet exclusionStr: string = "192.168,baidu.com" 635e41f4b71Sopenharmony_cilet exclusionArray: Array<string> = exclusionStr.split(','); 636e41f4b71Sopenharmony_cilet httpProxy: connection.HttpProxy = { 637e41f4b71Sopenharmony_ci host: "192.168.xx.xxx", 638e41f4b71Sopenharmony_ci port: 8080, 639e41f4b71Sopenharmony_ci exclusionList: exclusionArray 640e41f4b71Sopenharmony_ci}; 641e41f4b71Sopenharmony_ci 642e41f4b71Sopenharmony_cinetworkManager.setGlobalProxy(wantTemp, httpProxy).then(() => { 643e41f4b71Sopenharmony_ci console.info(`Succeeded in setting network global proxy`); 644e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 645e41f4b71Sopenharmony_ci console.error(`Failed to set network global proxy. Code: ${err.code}, message: ${err.message}`); 646e41f4b71Sopenharmony_ci}); 647e41f4b71Sopenharmony_ci``` 648e41f4b71Sopenharmony_ci 649e41f4b71Sopenharmony_ci## networkManager.getGlobalProxy 650e41f4b71Sopenharmony_ci 651e41f4b71Sopenharmony_cigetGlobalProxy(admin: Want, callback: AsyncCallback\<connection.HttpProxy>): void 652e41f4b71Sopenharmony_ci 653e41f4b71Sopenharmony_ciObtains the global network proxy through the specified device administrator application. This API uses an asynchronous callback to return the result. 654e41f4b71Sopenharmony_ci 655e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 656e41f4b71Sopenharmony_ci 657e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 658e41f4b71Sopenharmony_ci 659e41f4b71Sopenharmony_ci 660e41f4b71Sopenharmony_ci**Parameters** 661e41f4b71Sopenharmony_ci 662e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 663e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------------------------- | 664e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 665e41f4b71Sopenharmony_ci| callback | AsyncCallback<[connection.HttpProxy](../apis-network-kit/js-apis-net-connection.md#httpproxy10)> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 666e41f4b71Sopenharmony_ci 667e41f4b71Sopenharmony_ci**Error codes** 668e41f4b71Sopenharmony_ci 669e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 670e41f4b71Sopenharmony_ci 671e41f4b71Sopenharmony_ci| ID| Error Message | 672e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 673e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 674e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 675e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 676e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 677e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 678e41f4b71Sopenharmony_ci 679e41f4b71Sopenharmony_ci**Example** 680e41f4b71Sopenharmony_ci 681e41f4b71Sopenharmony_ci```ts 682e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 683e41f4b71Sopenharmony_cilet wantTemp: Want = { 684e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 685e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 686e41f4b71Sopenharmony_ci}; 687e41f4b71Sopenharmony_ci 688e41f4b71Sopenharmony_cinetworkManager.getGlobalProxy(wantTemp, (err, result) => { 689e41f4b71Sopenharmony_ci if (err) { 690e41f4b71Sopenharmony_ci console.error(`Failed to get network global proxy. Code: ${err.code}, message: ${err.message}`); 691e41f4b71Sopenharmony_ci return; 692e41f4b71Sopenharmony_ci } 693e41f4b71Sopenharmony_ci console.info(`Succeeded in getting network global proxy, result : ${JSON.stringify(result)}`); 694e41f4b71Sopenharmony_ci}); 695e41f4b71Sopenharmony_ci``` 696e41f4b71Sopenharmony_ci 697e41f4b71Sopenharmony_ci## networkManager.getGlobalProxy 698e41f4b71Sopenharmony_ci 699e41f4b71Sopenharmony_cigetGlobalProxy(admin: Want): Promise\<connection.HttpProxy> 700e41f4b71Sopenharmony_ci 701e41f4b71Sopenharmony_ciObtains the global network proxy through the specified device administrator application. This API uses a promise to return the result. 702e41f4b71Sopenharmony_ci 703e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 704e41f4b71Sopenharmony_ci 705e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 706e41f4b71Sopenharmony_ci 707e41f4b71Sopenharmony_ci 708e41f4b71Sopenharmony_ci**Parameters** 709e41f4b71Sopenharmony_ci 710e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 711e41f4b71Sopenharmony_ci| ----- | ----------------------------------- | ---- | ------- | 712e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 713e41f4b71Sopenharmony_ci 714e41f4b71Sopenharmony_ci**Return value** 715e41f4b71Sopenharmony_ci 716e41f4b71Sopenharmony_ci| Type | Description | 717e41f4b71Sopenharmony_ci| --------------------- | ------------------------- | 718e41f4b71Sopenharmony_ci| Promise<[connection.HttpProxy](../apis-network-kit/js-apis-net-connection.md#httpproxy10)> | Promise used to return the global HTTP proxy information obtained. | 719e41f4b71Sopenharmony_ci 720e41f4b71Sopenharmony_ci**Error codes** 721e41f4b71Sopenharmony_ci 722e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 723e41f4b71Sopenharmony_ci 724e41f4b71Sopenharmony_ci| ID| Error Message | 725e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 726e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 727e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 728e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 729e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 730e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 731e41f4b71Sopenharmony_ci 732e41f4b71Sopenharmony_ci**Example** 733e41f4b71Sopenharmony_ci 734e41f4b71Sopenharmony_ci```ts 735e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 736e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 737e41f4b71Sopenharmony_cilet wantTemp: Want = { 738e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 739e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 740e41f4b71Sopenharmony_ci}; 741e41f4b71Sopenharmony_ci 742e41f4b71Sopenharmony_cinetworkManager.getGlobalProxy(wantTemp).then(() => { 743e41f4b71Sopenharmony_ci console.info(`Succeeded in getting network global proxy`); 744e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 745e41f4b71Sopenharmony_ci console.error(`Failed to get network global proxy. Code: ${err.code}, message: ${err.message}`); 746e41f4b71Sopenharmony_ci}); 747e41f4b71Sopenharmony_ci``` 748e41f4b71Sopenharmony_ci 749e41f4b71Sopenharmony_ci## networkManager.addIptablesFilterRule 750e41f4b71Sopenharmony_ci 751e41f4b71Sopenharmony_ciaddIptablesFilterRule(admin: Want, filterRule: AddFilterRule, callback: AsyncCallback\<void>): void 752e41f4b71Sopenharmony_ci 753e41f4b71Sopenharmony_ciAdds a network packet filtering rule for devices through the specified device administrator application. This API uses an asynchronous callback to return the result. 754e41f4b71Sopenharmony_ci 755e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 756e41f4b71Sopenharmony_ci 757e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 758e41f4b71Sopenharmony_ci 759e41f4b71Sopenharmony_ci 760e41f4b71Sopenharmony_ci**Parameters** 761e41f4b71Sopenharmony_ci 762e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 763e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------------------------- | 764e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 765e41f4b71Sopenharmony_ci| filterRule | [AddFilterRule](#addfilterrule) | Yes | Network packet filtering rule to add. | 766e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 767e41f4b71Sopenharmony_ci 768e41f4b71Sopenharmony_ci**Error codes** 769e41f4b71Sopenharmony_ci 770e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 771e41f4b71Sopenharmony_ci 772e41f4b71Sopenharmony_ci| ID| Error Message | 773e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 774e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 775e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 776e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 777e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 778e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 779e41f4b71Sopenharmony_ci 780e41f4b71Sopenharmony_ci**Example** 781e41f4b71Sopenharmony_ci 782e41f4b71Sopenharmony_ci```ts 783e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 784e41f4b71Sopenharmony_cilet wantTemp: Want = { 785e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 786e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 787e41f4b71Sopenharmony_ci}; 788e41f4b71Sopenharmony_cilet filterRule: networkManager.AddFilterRule = { 789e41f4b71Sopenharmony_ci "ruleNo": 1, 790e41f4b71Sopenharmony_ci "srcAddr": "192.168.1.1-192.168.255.255", 791e41f4b71Sopenharmony_ci "destAddr": "10.1.1.1", 792e41f4b71Sopenharmony_ci "srcPort": "8080", 793e41f4b71Sopenharmony_ci "destPort": "8080", 794e41f4b71Sopenharmony_ci "uid": "9696", 795e41f4b71Sopenharmony_ci "method": networkManager.AddMethod.APPEND, 796e41f4b71Sopenharmony_ci "direction": networkManager.Direction.OUTPUT, 797e41f4b71Sopenharmony_ci "action": networkManager.Action.DENY, 798e41f4b71Sopenharmony_ci "protocol": networkManager.Protocol.UDP, 799e41f4b71Sopenharmony_ci} 800e41f4b71Sopenharmony_ci 801e41f4b71Sopenharmony_cinetworkManager.addIptablesFilterRule(wantTemp, filterRule, (err) => { 802e41f4b71Sopenharmony_ci if (err) { 803e41f4b71Sopenharmony_ci console.error(`Failed to set iptables filter rule. Code: ${err.code}, message: ${err.message}`); 804e41f4b71Sopenharmony_ci return; 805e41f4b71Sopenharmony_ci } 806e41f4b71Sopenharmony_ci console.info(`Succeeded in setting iptables filter rule`); 807e41f4b71Sopenharmony_ci}); 808e41f4b71Sopenharmony_ci``` 809e41f4b71Sopenharmony_ci 810e41f4b71Sopenharmony_ci## networkManager.addIptablesFilterRule 811e41f4b71Sopenharmony_ci 812e41f4b71Sopenharmony_ciaddIptablesFilterRule(admin: Want, filterRule: AddFilterRule): Promise\<void> 813e41f4b71Sopenharmony_ci 814e41f4b71Sopenharmony_ciAdds a network packet filtering rule for devices through the specified device administrator application. This API uses a promise to return the result. 815e41f4b71Sopenharmony_ci 816e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 817e41f4b71Sopenharmony_ci 818e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 819e41f4b71Sopenharmony_ci 820e41f4b71Sopenharmony_ci 821e41f4b71Sopenharmony_ci**Parameters** 822e41f4b71Sopenharmony_ci 823e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 824e41f4b71Sopenharmony_ci| ----- | ----------------------------------- | ---- | ------- | 825e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 826e41f4b71Sopenharmony_ci| filterRule | [AddFilterRule](#addfilterrule) | Yes | Network packet filtering rule to add. | 827e41f4b71Sopenharmony_ci 828e41f4b71Sopenharmony_ci**Return value** 829e41f4b71Sopenharmony_ci 830e41f4b71Sopenharmony_ci| Type | Description | 831e41f4b71Sopenharmony_ci| --------------------- | ------------------------- | 832e41f4b71Sopenharmony_ci| Promise<void> | Promise that returns no value. If the operation fails, an error object will be thrown. | 833e41f4b71Sopenharmony_ci 834e41f4b71Sopenharmony_ci**Error codes** 835e41f4b71Sopenharmony_ci 836e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 837e41f4b71Sopenharmony_ci 838e41f4b71Sopenharmony_ci| ID| Error Message | 839e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 840e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 841e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 842e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 843e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 844e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 845e41f4b71Sopenharmony_ci 846e41f4b71Sopenharmony_ci**Example** 847e41f4b71Sopenharmony_ci 848e41f4b71Sopenharmony_ci```ts 849e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 850e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 851e41f4b71Sopenharmony_cilet wantTemp: Want = { 852e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 853e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 854e41f4b71Sopenharmony_ci}; 855e41f4b71Sopenharmony_cilet filterRule: networkManager.AddFilterRule = { 856e41f4b71Sopenharmony_ci "ruleNo": 1, 857e41f4b71Sopenharmony_ci "srcAddr": "192.168.1.1-192.168.255.255", 858e41f4b71Sopenharmony_ci "destAddr": "10.1.1.1", 859e41f4b71Sopenharmony_ci "srcPort": "8080", 860e41f4b71Sopenharmony_ci "destPort": "8080", 861e41f4b71Sopenharmony_ci "uid": "9696", 862e41f4b71Sopenharmony_ci "method": networkManager.AddMethod.APPEND, 863e41f4b71Sopenharmony_ci "direction": networkManager.Direction.OUTPUT, 864e41f4b71Sopenharmony_ci "action": networkManager.Action.DENY, 865e41f4b71Sopenharmony_ci "protocol": networkManager.Protocol.UDP, 866e41f4b71Sopenharmony_ci} 867e41f4b71Sopenharmony_ci 868e41f4b71Sopenharmony_cinetworkManager.addIptablesFilterRule(wantTemp, filterRule).then(() => { 869e41f4b71Sopenharmony_ci console.info(`Succeeded in setting iptables filter rule`); 870e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 871e41f4b71Sopenharmony_ci console.error(`Failed to set iptables filter rule. Code: ${err.code}, message: ${err.message}`); 872e41f4b71Sopenharmony_ci}); 873e41f4b71Sopenharmony_ci``` 874e41f4b71Sopenharmony_ci 875e41f4b71Sopenharmony_ci## networkManager.removeIptablesFilterRule 876e41f4b71Sopenharmony_ci 877e41f4b71Sopenharmony_ciremoveIptablesFilterRule(admin: Want, filterRule: RemoveFilterRule, callback: AsyncCallback\<void>): void 878e41f4b71Sopenharmony_ci 879e41f4b71Sopenharmony_ciRemoves a network packet filtering rule through the specified device administrator application. This API uses an asynchronous callback to return the result. 880e41f4b71Sopenharmony_ci 881e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 882e41f4b71Sopenharmony_ci 883e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 884e41f4b71Sopenharmony_ci 885e41f4b71Sopenharmony_ci 886e41f4b71Sopenharmony_ci**Parameters** 887e41f4b71Sopenharmony_ci 888e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 889e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------------------------- | 890e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 891e41f4b71Sopenharmony_ci| filterRule | [RemoveFilterRule](#removefilterrule) | Yes | Network packet filtering rule to remove. | 892e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 893e41f4b71Sopenharmony_ci 894e41f4b71Sopenharmony_ci**Error codes** 895e41f4b71Sopenharmony_ci 896e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 897e41f4b71Sopenharmony_ci 898e41f4b71Sopenharmony_ci| ID| Error Message | 899e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 900e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 901e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 902e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 903e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 904e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 905e41f4b71Sopenharmony_ci 906e41f4b71Sopenharmony_ci**Example** 907e41f4b71Sopenharmony_ci 908e41f4b71Sopenharmony_ci```ts 909e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 910e41f4b71Sopenharmony_cilet wantTemp: Want = { 911e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 912e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 913e41f4b71Sopenharmony_ci}; 914e41f4b71Sopenharmony_cilet filterRule: networkManager.RemoveFilterRule = { 915e41f4b71Sopenharmony_ci "srcAddr": "192.168.1.1-192.168.255.255", 916e41f4b71Sopenharmony_ci "destAddr": "10.1.1.1", 917e41f4b71Sopenharmony_ci "srcPort": "8080", 918e41f4b71Sopenharmony_ci "destPort": "8080", 919e41f4b71Sopenharmony_ci "uid": "9696", 920e41f4b71Sopenharmony_ci "direction": networkManager.Direction.OUTPUT, 921e41f4b71Sopenharmony_ci "action": networkManager.Action.DENY, 922e41f4b71Sopenharmony_ci "protocol": networkManager.Protocol.UDP, 923e41f4b71Sopenharmony_ci} 924e41f4b71Sopenharmony_ci 925e41f4b71Sopenharmony_cinetworkManager.removeIptablesFilterRule(wantTemp, filterRule, (err) => { 926e41f4b71Sopenharmony_ci if (err) { 927e41f4b71Sopenharmony_ci console.error(`Failed to remove iptables filter rule. Code: ${err.code}, message: ${err.message}`); 928e41f4b71Sopenharmony_ci return; 929e41f4b71Sopenharmony_ci } 930e41f4b71Sopenharmony_ci console.info(`Succeeded in removing iptables filter rule`); 931e41f4b71Sopenharmony_ci}); 932e41f4b71Sopenharmony_ci``` 933e41f4b71Sopenharmony_ci 934e41f4b71Sopenharmony_ci## networkManager.removeIptablesFilterRule 935e41f4b71Sopenharmony_ci 936e41f4b71Sopenharmony_ciremoveIptablesFilterRule(admin: Want, filterRule: RemoveFilterRule): Promise\<void> 937e41f4b71Sopenharmony_ci 938e41f4b71Sopenharmony_ciRemoves a network packet filtering rule through the specified device administrator application. This API uses a promise to return the result. 939e41f4b71Sopenharmony_ci 940e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 941e41f4b71Sopenharmony_ci 942e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 943e41f4b71Sopenharmony_ci 944e41f4b71Sopenharmony_ci 945e41f4b71Sopenharmony_ci**Parameters** 946e41f4b71Sopenharmony_ci 947e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 948e41f4b71Sopenharmony_ci| ----- | ----------------------------------- | ---- | ------- | 949e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 950e41f4b71Sopenharmony_ci| filterRule | [RemoveFilterRule](#removefilterrule) | Yes | Network packet filtering rule to remove. | 951e41f4b71Sopenharmony_ci 952e41f4b71Sopenharmony_ci**Return value** 953e41f4b71Sopenharmony_ci 954e41f4b71Sopenharmony_ci| Type | Description | 955e41f4b71Sopenharmony_ci| --------------------- | ------------------------- | 956e41f4b71Sopenharmony_ci| Promise<void> | Promise that returns no value. If the operation fails, an error object will be thrown. | 957e41f4b71Sopenharmony_ci 958e41f4b71Sopenharmony_ci**Error codes** 959e41f4b71Sopenharmony_ci 960e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 961e41f4b71Sopenharmony_ci 962e41f4b71Sopenharmony_ci| ID| Error Message | 963e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 964e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 965e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 966e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 967e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 968e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 969e41f4b71Sopenharmony_ci 970e41f4b71Sopenharmony_ci**Example** 971e41f4b71Sopenharmony_ci 972e41f4b71Sopenharmony_ci```ts 973e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 974e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 975e41f4b71Sopenharmony_cilet wantTemp: Want = { 976e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 977e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 978e41f4b71Sopenharmony_ci}; 979e41f4b71Sopenharmony_cilet filterRule: networkManager.RemoveFilterRule = { 980e41f4b71Sopenharmony_ci "srcAddr": "192.168.1.1-192.168.255.255", 981e41f4b71Sopenharmony_ci "destAddr": "10.1.1.1", 982e41f4b71Sopenharmony_ci "srcPort": "8080", 983e41f4b71Sopenharmony_ci "destPort": "8080", 984e41f4b71Sopenharmony_ci "uid": "9696", 985e41f4b71Sopenharmony_ci "direction": networkManager.Direction.OUTPUT, 986e41f4b71Sopenharmony_ci "action": networkManager.Action.DENY, 987e41f4b71Sopenharmony_ci "protocol": networkManager.Protocol.UDP, 988e41f4b71Sopenharmony_ci} 989e41f4b71Sopenharmony_ci 990e41f4b71Sopenharmony_cinetworkManager.removeIptablesFilterRule(wantTemp, filterRule).then(() => { 991e41f4b71Sopenharmony_ci console.info(`Succeeded in removing iptables filter rule`); 992e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 993e41f4b71Sopenharmony_ci console.error(`Failed to remove iptables filter rule. Code: ${err.code}, message: ${err.message}`); 994e41f4b71Sopenharmony_ci}); 995e41f4b71Sopenharmony_ci``` 996e41f4b71Sopenharmony_ci 997e41f4b71Sopenharmony_ci## networkManager.listIptablesFilterRules 998e41f4b71Sopenharmony_ci 999e41f4b71Sopenharmony_cilistIptablesFilterRules(admin: Want, callback: AsyncCallback\<string>): void 1000e41f4b71Sopenharmony_ci 1001e41f4b71Sopenharmony_ciObtains network packet filtering rules through the specified device administrator application. This API uses an asynchronous callback to return the result. 1002e41f4b71Sopenharmony_ci 1003e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 1004e41f4b71Sopenharmony_ci 1005e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1006e41f4b71Sopenharmony_ci 1007e41f4b71Sopenharmony_ci 1008e41f4b71Sopenharmony_ci**Parameters** 1009e41f4b71Sopenharmony_ci 1010e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1011e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------------------------- | 1012e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 1013e41f4b71Sopenharmony_ci| callback | AsyncCallback<string> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 1014e41f4b71Sopenharmony_ci 1015e41f4b71Sopenharmony_ci**Error codes** 1016e41f4b71Sopenharmony_ci 1017e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 1018e41f4b71Sopenharmony_ci 1019e41f4b71Sopenharmony_ci| ID| Error Message | 1020e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 1021e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 1022e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 1023e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1024e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1025e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1026e41f4b71Sopenharmony_ci 1027e41f4b71Sopenharmony_ci**Example** 1028e41f4b71Sopenharmony_ci 1029e41f4b71Sopenharmony_ci```ts 1030e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 1031e41f4b71Sopenharmony_cilet wantTemp: Want = { 1032e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 1033e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 1034e41f4b71Sopenharmony_ci}; 1035e41f4b71Sopenharmony_ci 1036e41f4b71Sopenharmony_cinetworkManager.listIptablesFilterRules(wantTemp, (err, result) => { 1037e41f4b71Sopenharmony_ci if (err) { 1038e41f4b71Sopenharmony_ci console.error(`Failed to get iptables filter rule. Code: ${err.code}, message: ${err.message}`); 1039e41f4b71Sopenharmony_ci return; 1040e41f4b71Sopenharmony_ci } 1041e41f4b71Sopenharmony_ci console.info(`Succeeded in getting iptables filter rule, result : ${result}`); 1042e41f4b71Sopenharmony_ci}); 1043e41f4b71Sopenharmony_ci``` 1044e41f4b71Sopenharmony_ci 1045e41f4b71Sopenharmony_ci## networkManager.listIptablesFilterRules 1046e41f4b71Sopenharmony_ci 1047e41f4b71Sopenharmony_cilistIptablesFilterRules(admin: Want): Promise\<string> 1048e41f4b71Sopenharmony_ci 1049e41f4b71Sopenharmony_ciObtains network packet filtering rules through the specified device administrator application. This API uses a promise to return the result. 1050e41f4b71Sopenharmony_ci 1051e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 1052e41f4b71Sopenharmony_ci 1053e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1054e41f4b71Sopenharmony_ci 1055e41f4b71Sopenharmony_ci 1056e41f4b71Sopenharmony_ci**Parameters** 1057e41f4b71Sopenharmony_ci 1058e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1059e41f4b71Sopenharmony_ci| ----- | ----------------------------------- | ---- | ------- | 1060e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 1061e41f4b71Sopenharmony_ci 1062e41f4b71Sopenharmony_ci**Return value** 1063e41f4b71Sopenharmony_ci 1064e41f4b71Sopenharmony_ci| Type | Description | 1065e41f4b71Sopenharmony_ci| --------------------- | ------------------------- | 1066e41f4b71Sopenharmony_ci| Promise<string> | Promise used to return the network packet filtering rules obtained. | 1067e41f4b71Sopenharmony_ci 1068e41f4b71Sopenharmony_ci**Error codes** 1069e41f4b71Sopenharmony_ci 1070e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 1071e41f4b71Sopenharmony_ci 1072e41f4b71Sopenharmony_ci| ID| Error Message | 1073e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 1074e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 1075e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 1076e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1077e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1078e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1079e41f4b71Sopenharmony_ci 1080e41f4b71Sopenharmony_ci**Example** 1081e41f4b71Sopenharmony_ci 1082e41f4b71Sopenharmony_ci```ts 1083e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 1084e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1085e41f4b71Sopenharmony_cilet wantTemp: Want = { 1086e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 1087e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 1088e41f4b71Sopenharmony_ci}; 1089e41f4b71Sopenharmony_ci 1090e41f4b71Sopenharmony_cinetworkManager.listIptablesFilterRules(wantTemp).then((result) => { 1091e41f4b71Sopenharmony_ci console.info(`Succeeded in getting iptables filter rule, result: ${result}`); 1092e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 1093e41f4b71Sopenharmony_ci console.error(`Failed to remove iptables filter rule. Code: ${err.code}, message: ${err.message}`); 1094e41f4b71Sopenharmony_ci}); 1095e41f4b71Sopenharmony_ci``` 1096e41f4b71Sopenharmony_ci 1097e41f4b71Sopenharmony_ci## AddFilterRule 1098e41f4b71Sopenharmony_ci 1099e41f4b71Sopenharmony_ciNetwork packet filtering rule to add. 1100e41f4b71Sopenharmony_ci 1101e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1102e41f4b71Sopenharmony_ci 1103e41f4b71Sopenharmony_ci 1104e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1105e41f4b71Sopenharmony_ci| ----------- | --------| ---- | ------------------------------- | 1106e41f4b71Sopenharmony_ci| ruleNo | number | No | Sequence number of the rule.| 1107e41f4b71Sopenharmony_ci| srcAddr | string | No | Source IP address.| 1108e41f4b71Sopenharmony_ci| destAddr | string | No | Destination IP address.| 1109e41f4b71Sopenharmony_ci| srcPort | string | No | Port of the source IP address.| 1110e41f4b71Sopenharmony_ci| destPort | string | No | Port of the destination IP address.| 1111e41f4b71Sopenharmony_ci| uid | string | No | UID of the application.| 1112e41f4b71Sopenharmony_ci| method | [AddMethod](#addmethod) | Yes | Method used to add the data packets.| 1113e41f4b71Sopenharmony_ci| direction | [Direction](js-apis-enterprise-networkManager.md#direction) | Yes | Direction chains to which the rule applies.| 1114e41f4b71Sopenharmony_ci| action | [Action](js-apis-enterprise-networkManager.md#action) | Yes | Action to take, that is, receive or discard data packets.| 1115e41f4b71Sopenharmony_ci| protocol | [Protocol](js-apis-enterprise-networkManager.md#protocol) | No | Network protocol.| 1116e41f4b71Sopenharmony_ci 1117e41f4b71Sopenharmony_ci## RemoveFilterRule 1118e41f4b71Sopenharmony_ci 1119e41f4b71Sopenharmony_ciNetwork packet filtering rule to remove. 1120e41f4b71Sopenharmony_ci 1121e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1122e41f4b71Sopenharmony_ci 1123e41f4b71Sopenharmony_ci 1124e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1125e41f4b71Sopenharmony_ci| ----------- | --------| ---- | ------------------------------- | 1126e41f4b71Sopenharmony_ci| srcAddr | string | No | Source IP address.| 1127e41f4b71Sopenharmony_ci| destAddr | string | No | Destination IP address.| 1128e41f4b71Sopenharmony_ci| srcPort | string | No | Port of the source IP address.| 1129e41f4b71Sopenharmony_ci| destPort | string | No | Port of the destination IP address.| 1130e41f4b71Sopenharmony_ci| uid | string | No | UID of the application.| 1131e41f4b71Sopenharmony_ci| direction | [Direction](js-apis-enterprise-networkManager.md#direction) | Yes | Direction chains to which the rule applies.| 1132e41f4b71Sopenharmony_ci| action | [Action](js-apis-enterprise-networkManager.md#action) | No | Action to take, that is, receive or discard data packets.| 1133e41f4b71Sopenharmony_ci| protocol | [Protocol](js-apis-enterprise-networkManager.md#protocol) | No | Network protocol.| 1134e41f4b71Sopenharmony_ci 1135e41f4b71Sopenharmony_ci## AddMethod 1136e41f4b71Sopenharmony_ci 1137e41f4b71Sopenharmony_ciEnumerates the methods used to add the network packets. 1138e41f4b71Sopenharmony_ci 1139e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1140e41f4b71Sopenharmony_ci 1141e41f4b71Sopenharmony_ci 1142e41f4b71Sopenharmony_ci| Name| Value| Description| 1143e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 1144e41f4b71Sopenharmony_ci| APPEND | 0 | Append the packet.| 1145e41f4b71Sopenharmony_ci| INSERT | 1 | Insert the packet.| 1146