1# @ohos.enterprise.networkManager (Network Management) 2 3The **networkManager** module provides APIs for network management of enterprise devices, including obtaining the device IP address and MAC address. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> 9> The APIs of this module can be used only in the stage model. 10> 11> The APIs of this module can be called only by a [device administrator application](../../mdm/mdm-kit-guide.md#introduction) that is enabled. 12> 13 14## Modules to Import 15 16```ts 17import { networkManager } from '@kit.MDMKit'; 18``` 19 20## networkManager.getAllNetworkInterfacesSync 21 22getAllNetworkInterfacesSync(admin: Want): Array<string> 23 24Obtains all activated wired network interfaces. 25 26**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 27 28**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 29 30 31**Parameters** 32 33| Name| Type | Mandatory| Description | 34| ------ | ------------------------------------------------------- | ---- | -------------- | 35| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 36 37**Return value** 38 39| Type | Description | 40| ------------------- | ---------------------- | 41| Array<string> | Names of all activated wired network interfaces.| 42 43**Error codes** 44 45For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 46 47| ID| Error Message | 48| -------- | ------------------------------------------------------------ | 49| 9200001 | The application is not an administrator application of the device. | 50| 9200002 | The administrator application does not have permission to manage the device. | 51| 201 | Permission verification failed. The application does not have the permission required to call the API. | 52| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 53 54**Example** 55 56```ts 57import { Want } from '@kit.AbilityKit'; 58let wantTemp: Want = { 59 bundleName: 'com.example.myapplication', 60 abilityName: 'EntryAbility', 61}; 62 63try { 64 let result: Array<string> = networkManager.getAllNetworkInterfacesSync(wantTemp); 65 console.info(`Succeeded in getting all network interfaces, result : ${JSON.stringify(result)}`); 66} catch (err) { 67 console.error(`Failed to get all network interfaces. Code: ${err.code}, message: ${err.message}`); 68} 69``` 70 71## networkManager.getIpAddressSync 72 73getIpAddressSync(admin: Want, networkInterface: string): string 74 75Obtains the device IP address based on the network interface. 76 77**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 78 79**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 80 81 82**Parameters** 83 84| Name | Type | Mandatory| Description | 85| ---------------- | ------------------------------------------------------- | ---- | -------------- | 86| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 87| networkInterface | string | Yes | Network port.| 88 89**Return value** 90 91| Type | Description | 92| ------ | ---------------- | 93| string | IP address of the network interface specified by the device.| 94 95**Error codes** 96 97For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 98 99| ID| Error Message | 100| -------- | ------------------------------------------------------------ | 101| 9200001 | The application is not an administrator application of the device. | 102| 9200002 | The administrator application does not have permission to manage the device. | 103| 201 | Permission verification failed. The application does not have the permission required to call the API. | 104| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 105 106**Example** 107 108```ts 109import { Want } from '@kit.AbilityKit'; 110let wantTemp: Want = { 111 bundleName: 'com.example.myapplication', 112 abilityName: 'EntryAbility', 113}; 114 115try { 116 let result: string = networkManager.getIpAddressSync(wantTemp, 'eth0'); 117 console.info(`Succeeded in getting ip address, result : ${result}`); 118} catch (err) { 119 console.error(`Failed to get ip address. Code: ${err.code}, message: ${err.message}`); 120} 121``` 122 123## networkManager.getMacSync 124 125getMacSync(admin: Want, networkInterface: string): string 126 127Obtains the MAC address of a device based on the network interface. 128 129**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 130 131**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 132 133 134**Parameters** 135 136| Name | Type | Mandatory| Description | 137| ---------------- | ------------------------------------------------------- | ---- | -------------- | 138| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 139| networkInterface | string | Yes | Network port.| 140 141**Return value** 142 143| Type | Description | 144| ------ | ----------------- | 145| string | MAC address of the network interface specified by the device.| 146 147**Error codes** 148 149For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 150 151| ID| Error Message | 152| -------- | ------------------------------------------------------------ | 153| 9200001 | The application is not an administrator application of the device. | 154| 9200002 | The administrator application does not have permission to manage the device. | 155| 201 | Permission verification failed. The application does not have the permission required to call the API. | 156| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 157 158**Example** 159 160```ts 161import { Want } from '@kit.AbilityKit'; 162let wantTemp: Want = { 163 bundleName: 'com.example.myapplication', 164 abilityName: 'EntryAbility', 165}; 166 167try { 168 let result: string = networkManager.getMacSync(wantTemp, 'eth0'); 169 console.info(`Succeeded in getting mac, result : ${result}`); 170} catch (err) { 171 console.error(`Failed to get mac. Code: ${err.code}, message: ${err.message}`); 172} 173``` 174 175## networkManager.isNetworkInterfaceDisabledSync 176 177isNetworkInterfaceDisabledSync(admin: Want, networkInterface: string): boolean 178 179Queries whether a specified network interface is disabled. 180 181**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 182 183**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 184 185 186**Parameters** 187 188| Name | Type | Mandatory| Description | 189| ---------------- | ------------------------------------------------------- | ---- | -------------- | 190| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 191| networkInterface | string | Yes | Network port.| 192 193**Return value** 194 195| Type | Description | 196| ------- | ------------------------------------------------------------ | 197| boolean | Returns **true** if the network port is disabled; returns **false** otherwise.| 198 199**Error codes** 200 201For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 202 203| ID| Error Message | 204| -------- | ------------------------------------------------------------ | 205| 9200001 | The application is not an administrator application of the device. | 206| 9200002 | The administrator application does not have permission to manage the device. | 207| 201 | Permission verification failed. The application does not have the permission required to call the API. | 208| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 209 210**Example** 211 212```ts 213import { Want } from '@kit.AbilityKit'; 214let wantTemp: Want = { 215 bundleName: 'com.example.myapplication', 216 abilityName: 'EntryAbility', 217}; 218 219try { 220 let result: boolean = networkManager.isNetworkInterfaceDisabledSync(wantTemp, 'eth0'); 221 console.info(`Succeeded in querying network interface is disabled or not, result : ${result}`); 222} catch (err) { 223 console.error(`Failed to query network interface is disabled or not. Code: ${err.code}, message: ${err.message}`); 224} 225``` 226 227## networkManager.setNetworkInterfaceDisabledSync 228 229setNetworkInterfaceDisabledSync(admin: Want, networkInterface: string, isDisabled: boolean): void 230 231Disables the device from using the specified network interface. 232 233**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 234 235**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 236 237 238**Parameters** 239 240| Name | Type | Mandatory| Description | 241| ---------------- | ------------------------------------------------------- | ---- | ------------------------------------------------- | 242| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 243| networkInterface | string | Yes | Network port. | 244| 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.| 245 246**Error codes** 247 248For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 249 250| ID| Error Message | 251| -------- | ------------------------------------------------------------ | 252| 9200001 | The application is not an administrator application of the device. | 253| 9200002 | The administrator application does not have permission to manage the device. | 254| 201 | Permission verification failed. The application does not have the permission required to call the API. | 255| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 256 257**Example** 258 259```ts 260import { Want } from '@kit.AbilityKit'; 261import { BusinessError } from '@kit.BasicServicesKit'; 262let wantTemp: Want = { 263 bundleName: 'com.example.myapplication', 264 abilityName: 'EntryAbility', 265}; 266 267try { 268 networkManager.setNetworkInterfaceDisabledSync(wantTemp, 'eth0', true); 269 console.info(`Succeeded in setting network interface disabled`); 270} catch (err) { 271 console.error(`Failed to set network interface disabled. Code: ${err.code}, message: ${err.message}`); 272} 273``` 274 275## networkManager.setGlobalProxySync 276 277setGlobalProxySync(admin: Want, httpProxy: connection.HttpProxy): void 278 279Sets the global network proxy. 280 281**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 282 283**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 284 285 286**Parameters** 287 288| Name | Type | Mandatory| Description | 289| --------- | ------------------------------------------------------------ | ---- | -------------------------- | 290| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 291| httpProxy | [connection.HttpProxy](../apis-network-kit/js-apis-net-connection.md#httpproxy10) | Yes | Global HTTP proxy to set.| 292 293**Error codes** 294 295For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 296 297| ID| Error Message | 298| -------- | ------------------------------------------------------------ | 299| 9200001 | The application is not an administrator application of the device. | 300| 9200002 | The administrator application does not have permission to manage the device. | 301| 201 | Permission verification failed. The application does not have the permission required to call the API. | 302| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 303 304**Example** 305 306```ts 307import { Want } from '@kit.AbilityKit'; 308import { connection } from '@kit.NetworkKit'; 309let wantTemp: Want = { 310 bundleName: 'com.example.myapplication', 311 abilityName: 'EntryAbility', 312}; 313let exclusionStr: string = "192.168,baidu.com" 314let exclusionArray: Array<string> = exclusionStr.split(','); 315let httpProxy: connection.HttpProxy = { 316 host: "192.168.xx.xxx", 317 port: 8080, 318 exclusionList: exclusionArray 319}; 320 321try { 322 networkManager.setGlobalProxySync(wantTemp, httpProxy); 323 console.info(`Succeeded in setting network global proxy.`); 324} catch (err) { 325 console.error(`Failed to set network global proxy. Code: ${err.code}, message: ${err.message}`); 326} 327``` 328 329## networkManager.setGlobalProxyForAccount<sup>15+</sup> 330 331setGlobalProxyForAccount(admin: Want, httpProxy: connection.HttpProxy, accountId: number): void 332 333Sets the network proxy of a specified user. Currently, only 2-in-1 devices are supported. 334 335**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 336 337**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 338 339 340**Parameters** 341 342| Name | Type | Mandatory| Description | 343| --------- | ------------------------------------------------------------ | ---- | -------------------------- | 344| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 345| accountId | number | Yes | User ID, which must be greater than or equal to 0.<br> You can call [getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9-1) of **@ohos.account.osAccount** to obtain the user ID.| 346| httpProxy | [connection.HttpProxy](../apis-network-kit/js-apis-net-connection.md#httpproxy10) | Yes | HTTP proxy configuration of the network.| 347 348**Error codes** 349 350For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 351 352| ID| Error Message | 353| -------- | ------------------------------------------------------------ | 354| 9200001 | The application is not an administrator application of the device. | 355| 9200002 | The administrator application does not have permission to manage the device. | 356| 201 | Permission verification failed. The application does not have the permission required to call the API. | 357| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 358 359**Example** 360 361```ts 362import { Want } from '@kit.AbilityKit'; 363import { connection } from '@kit.NetworkKit'; 364let wantTemp: Want = { 365 bundleName: 'com.example.myapplication', 366 abilityName: 'EntryAbility', 367}; 368let httpProxy: connection.HttpProxy = { 369 host: '192.168.xx.xxx', 370 port: 8080, 371 exclusionList: ['192.168', 'baidu.com'] 372}; 373 374try { 375 networkManager.setGlobalProxyForAccount(wantTemp, httpProxy, 100); 376 console.info(`Succeeded in setting network global proxy.`); 377} catch (err) { 378 console.error(`Failed to set network global proxy. Code: ${err.code}, message: ${err.message}`); 379} 380``` 381 382## networkManager.getGlobalProxySync 383 384getGlobalProxySync(admin: Want): connection.HttpProxy 385 386Obtains the global network proxy. 387 388**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 389 390**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 391 392 393**Parameters** 394 395| Name| Type | Mandatory| Description | 396| ------ | ------------------------------------------------------- | ---- | -------------- | 397| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 398 399**Return value** 400 401| Type | Description | 402| ------------------------------------------------------------ | ------------------------------ | 403| [connection.HttpProxy](../apis-network-kit/js-apis-net-connection.md#httpproxy10) | Global HTTP proxy configuration obtained.| 404 405**Error codes** 406 407For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 408 409| ID| Error Message | 410| -------- | ------------------------------------------------------------ | 411| 9200001 | The application is not an administrator application of the device. | 412| 9200002 | The administrator application does not have permission to manage the device. | 413| 201 | Permission verification failed. The application does not have the permission required to call the API. | 414| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 415 416**Example** 417 418```ts 419import { Want } from '@kit.AbilityKit'; 420import { connection } from '@kit.NetworkKit'; 421let wantTemp: Want = { 422 bundleName: 'com.example.myapplication', 423 abilityName: 'EntryAbility', 424}; 425 426try { 427 let result: connection.HttpProxy = networkManager.getGlobalProxySync(wantTemp); 428 console.info(`Succeeded in getting network global proxy, result : ${JSON.stringify(result)}`); 429} catch (err) { 430 console.error(`Failed to get network global proxy. Code: ${err.code}, message: ${err.message}`); 431} 432``` 433 434## networkManager.getGlobalProxyForAccount<sup>15+</sup> 435 436getGlobalProxyForAccount(admin: Want, accountId: number): connection.HttpProxy 437 438Obtains the network proxy of a specified user. Currently, only 2-in-1 devices are supported. 439 440**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 441 442**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 443 444 445**Parameters** 446 447| Name| Type | Mandatory| Description | 448| ------ | ------------------------------------------------------- | ---- | -------------- | 449| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 450| accountId | number | Yes | User ID, which must be greater than or equal to 0.<br> You can call [getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9-1) of **@ohos.account.osAccount** to obtain the user ID.| 451 452**Return value** 453 454| Type | Description | 455| ------------------------------------------------------------ | ------------------------------ | 456| [connection.HttpProxy](../apis-network-kit/js-apis-net-connection.md#httpproxy10) | HTTP proxy configuration of the network.| 457 458**Error codes** 459 460For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 461 462| ID| Error Message | 463| -------- | ------------------------------------------------------------ | 464| 9200001 | The application is not an administrator application of the device. | 465| 9200002 | The administrator application does not have permission to manage the device. | 466| 201 | Permission verification failed. The application does not have the permission required to call the API. | 467| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 468 469**Example** 470 471```ts 472import { Want } from '@kit.AbilityKit'; 473import { connection } from '@kit.NetworkKit'; 474let wantTemp: Want = { 475 bundleName: 'com.example.myapplication', 476 abilityName: 'EntryAbility', 477}; 478 479try { 480 let result: connection.HttpProxy = networkManager.getGlobalProxyForAccount(wantTemp, 100); 481 console.info(`Succeeded in getting network global proxy, result : ${JSON.stringify(result)}`); 482} catch (err) { 483 console.error(`Failed to get network global proxy. Code: ${err.code}, message: ${err.message}`); 484} 485``` 486 487## networkManager.addFirewallRule 488 489addFirewallRule(admin: Want, firewallRule: FirewallRule): void 490 491Adds firewall rules for the device.<br> 492After a rule with [Action](#action) set to **ALLOW** is added, a rule with **Action** set to **DENY** is added by default to discard or intercept all network data packets that do not meet the **ALLOW** rule. 493 494**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 495 496**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 497 498 499**Parameters** 500 501| Name | Type | Mandatory| Description | 502| ------------ | ------------------------------------------------------- | ---- | -------------------- | 503| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 504| firewallRule | [FirewallRule](#firewallrule) | Yes | Firewall rule to add.| 505 506**Error codes** 507 508For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 509 510| ID| Error Message | 511| -------- | ------------------------------------------------------------ | 512| 9200001 | The application is not an administrator application of the device. | 513| 9200002 | The administrator application does not have permission to manage the device. | 514| 201 | Permission verification failed. The application does not have the permission required to call the API. | 515| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 516 517**Example** 518 519```ts 520import { Want } from '@kit.AbilityKit'; 521 522let wantTemp: Want = { 523 bundleName: 'com.example.myapplication', 524 abilityName: 'EntryAbility', 525}; 526let firewallRule: networkManager.FirewallRule = { 527 "srcAddr": "192.168.1.1-192.188.22.66", 528 "destAddr": "10.1.1.1", 529 "srcPort": "8080", 530 "destPort": "8080", 531 "appUid": "9696", 532 "direction": networkManager.Direction.OUTPUT, 533 "action": networkManager.Action.DENY, 534 "protocol": networkManager.Protocol.UDP, 535} 536 537networkManager.addFirewallRule(wantTemp, firewallRule); 538``` 539 540## networkManager.removeFirewallRule 541 542removeFirewallRule(admin: Want, firewallRule?: FirewallRule): void 543 544Removes a firewall rule.<br> 545If there is no rule with [Action](#action) being **ALLOW** after the rule is removed, the **DENY** rules that are added by default with [addFirewallRule](#networkmanageraddfirewallrule) will be removed. 546 547**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 548 549**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 550 551 552**Parameters** 553 554| Name | Type | Mandatory| Description | 555| ------------ | ------------------------------------------------------- | ---- | ---------------------------------------------------- | 556| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 557| firewallRule | [FirewallRule](#firewallrule) | No | Firewall rule to remove. If the value is empty, all firewall rules will be removed.| 558 559**Error codes** 560 561For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 562 563| ID| Error Message | 564| -------- | ------------------------------------------------------------ | 565| 9200001 | The application is not an administrator application of the device. | 566| 9200002 | The administrator application does not have permission to manage the device. | 567| 201 | Permission verification failed. The application does not have the permission required to call the API. | 568| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 569 570**Example** 571 572```ts 573import { Want } from '@kit.AbilityKit'; 574 575let wantTemp: Want = { 576 bundleName: 'com.example.myapplication', 577 abilityName: 'EntryAbility', 578}; 579// Remove the specified firewall rule. 580let firewallRule: networkManager.FirewallRule = { 581 "srcAddr": "192.168.1.1-192.188.22.66", 582 "destAddr": "10.1.1.1", 583 "srcPort": "8080", 584 "destPort": "8080", 585 "appUid": "9696", 586 "direction": networkManager.Direction.OUTPUT, 587 "action": networkManager.Action.DENY, 588 "protocol": networkManager.Protocol.UDP, 589} 590networkManager.removeFirewallRule(wantTemp, firewallRule); 591 592// Remove all firewall rules. 593networkManager.removeFirewallRule(wantTemp); 594``` 595 596## networkManager.getFirewallRules 597 598getFirewallRules(admin: Want): Array\<FirewallRule> 599 600Queries firewall rules of a device. 601 602**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 603 604**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 605 606 607**Parameters** 608 609| Name| Type | Mandatory| Description | 610| ------ | ------------------------------------------------------- | ---- | -------------- | 611| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 612 613**Return value** 614 615| Type | Description | 616| ------------------------------------- | ------------------------------------------------------------ | 617| Array\<[FirewallRule](#firewallrule)> | A list of firewall rules configured for the device is returned. If the operation fails, an exception will be thrown.| 618 619**Error codes** 620 621For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 622 623| ID| Error Message | 624| -------- | ------------------------------------------------------------ | 625| 9200001 | The application is not an administrator application of the device. | 626| 9200002 | The administrator application does not have permission to manage the device. | 627| 201 | Permission verification failed. The application does not have the permission required to call the API. | 628| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 629 630**Example** 631 632```ts 633import { Want } from '@kit.AbilityKit'; 634 635let wantTemp: Want = { 636 bundleName: 'com.example.myapplication', 637 abilityName: 'EntryAbility', 638}; 639let firewallRule: Array<networkManager.FirewallRule>; 640firewallRule = networkManager.getFirewallRules(wantTemp); 641``` 642 643## networkManager.addDomainFilterRule 644 645addDomainFilterRule(admin: Want, domainFilterRule: DomainFilterRule): void 646 647Adds domain name filtering rules for the device.<br> 648After a rule with [Action](#action) set to **ALLOW** is added, a rule with **Action** set to **DENY** is added by default to discard or intercept all packets for domain name resolution that do not meet the **ALLOW** rule. 649 650**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 651 652**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 653 654 655**Parameters** 656 657| Name | Type | Mandatory| Description | 658| ---------------- | ------------------------------------------------------- | ---- | ------------------ | 659| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 660| domainFilterRule | [DomainFilterRule](#domainfilterrule) | Yes | Domain name filtering rule to add.| 661 662**Error codes** 663 664For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 665 666| ID| Error Message | 667| -------- | ------------------------------------------------------------ | 668| 9200001 | The application is not an administrator application of the device. | 669| 9200002 | The administrator application does not have permission to manage the device. | 670| 201 | Permission verification failed. The application does not have the permission required to call the API. | 671| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 672 673**Example** 674 675```ts 676import { Want } from '@kit.AbilityKit'; 677 678let wantTemp: Want = { 679 bundleName: 'com.example.myapplication', 680 abilityName: 'EntryAbility', 681}; 682let domainFilterRule: networkManager.DomainFilterRule = { 683 "domainName": "www.example.com", 684 "appUid": "9696", 685 "action": networkManager.Action.DENY, 686} 687 688networkManager.addDomainFilterRule(wantTemp, domainFilterRule); 689``` 690 691## networkManager.removeDomainFilterRule 692 693removeDomainFilterRule(admin: Want, domainFilterRule?: DomainFilterRule): void 694 695Removes the domain name filtering rules.<br> 696If there is no rule with [Action](#action) being **ALLOW** after the rule is removed, the **DENY** rules that are added by default with [addDomainFilterRule](#networkmanageradddomainfilterrule) will be removed. 697 698**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 699 700**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 701 702 703**Parameters** 704 705| Name | Type | Mandatory| Description | 706| ---------------- | ------------------------------------------------------- | ---- | ------------------------------------------------ | 707| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 708| domainFilterRule | [DomainFilterRule](#domainfilterrule) | No | Domain name filtering rule to remove. If the value is empty, all domain name filtering rules will be removed.| 709 710**Error codes** 711 712For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 713 714| ID| Error Message | 715| -------- | ------------------------------------------------------------ | 716| 9200001 | The application is not an administrator application of the device. | 717| 9200002 | The administrator application does not have permission to manage the device. | 718| 201 | Permission verification failed. The application does not have the permission required to call the API. | 719| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 720 721**Example** 722 723```ts 724import { Want } from '@kit.AbilityKit'; 725 726let wantTemp: Want = { 727 bundleName: 'com.example.myapplication', 728 abilityName: 'EntryAbility', 729}; 730// Remove the specified domain name filtering rule. 731let domainFilterRule: networkManager.DomainFilterRule = { 732 "domainName": "www.example.com", 733 "appUid": "9696", 734 "action": networkManager.Action.DENY, 735} 736networkManager.removeDomainFilterRule(wantTemp, domainFilterRule); 737 738// Remove all domain name filtering rules. 739networkManager.removeDomainFilterRule(wantTemp); 740``` 741 742## networkManager.getDomainFilterRules 743 744getDomainFilterRules(admin: Want): Array\<DomainFilterRule> 745 746Queries domain name filtering rules. 747 748**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 749 750**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 751 752 753**Parameters** 754 755| Name| Type | Mandatory| Description | 756| ------ | ------------------------------------------------------- | ---- | -------------- | 757| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 758 759**Return value** 760 761| Type | Description | 762| --------------------------------------------- | ------------------------------------------------------------ | 763| Array\<[DomainFilterRule](#domainfilterrule)> | A list of domain name filtering rules configured for the device is returned. If the operation fails, an exception will be thrown.| 764 765**Error codes** 766 767For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 768 769| ID| Error Message | 770| -------- | ------------------------------------------------------------ | 771| 9200001 | The application is not an administrator application of the device. | 772| 9200002 | The administrator application does not have permission to manage the device. | 773| 201 | Permission verification failed. The application does not have the permission required to call the API. | 774| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 775 776**Example** 777 778```ts 779import { Want } from '@kit.AbilityKit'; 780 781let wantTemp: Want = { 782 bundleName: 'com.example.myapplication', 783 abilityName: 'EntryAbility', 784}; 785let domainFilterRule: Array<networkManager.DomainFilterRule>; 786domainFilterRule = networkManager.getDomainFilterRules(wantTemp); 787``` 788 789## FirewallRule 790 791Represents a firewall rule. 792 793**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 794 795 796| Name | Type | Mandatory| Description | 797| --------- | ----------------------- | ---- | ------------------------------------------------------------ | 798| srcAddr | string | No | Source IP address. An IP address segment, for example, **192.168.0.0/22** or **192.168.1.100-192.168.1.200** is supported.| 799| destAddr | string | No | Destination IP address. An IP address segment, for example, **192.168.0.0/22** or **192.168.1.100-192.168.1.200** is supported.| 800| srcPort | string | No | Source port. | 801| destPort | string | No | Destination port. | 802| appUid | string | No | UID of the application. | 803| direction | [Direction](#direction) | No | Direction chains to which the rule applies.<br>This parameter is mandatory when a firewall filtering rule is added.<br>This parameter is optional when a firewall is removed. If this parameter is left empty, all [Direction](#direction) chains are cleared, and **srcAddr**, **destAddr**, **srcPort**, **destPort**, and **appUid** must be also left empty.| 804| action | [Action](#action) | No | Action to take, that is, receive or discard the data packets.<br>This parameter is mandatory when a firewall rule is added.<br>This parameter is optional when a firewall is removed. If this parameter is left empty, all [Action](#action) chains are cleared, and **srcAddr**, **destAddr**, **srcPort**, **destPort**, and **appUid** must be also left empty.| 805| protocol | [Protocol](#protocol) | No | Network protocol. If this parameter is set to **ALL** or **ICMP**, **srcPort** and **destPort** cannot be set.| 806 807## DomainFilterRule 808 809Represents a domain name filtering rule. 810 811**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 812 813 814| Name | Type | Mandatory| Description | 815| ---------- | ----------------- | ---- | ------------------------------------------------------------ | 816| domainName | string | No | Domain name. This parameter is mandatory when a domain name filtering rule is added. | 817| appUid | string | No | UID of the application. | 818| action | [Action](#action) | No | Action to take, that is, receive or discard the data packets.<br>This parameter is mandatory when a domain name filtering rule is added.<br>This parameter is optional when a domain name filtering rule is removed. If this parameter is left empty, all [Action](#action) chains are cleared, and **domainName** and **appUid** must be also left empty.| 819| direction<sup>15+</sup> | [Direction](#direction) | No|Direction chains to which the rule applies.<br>This parameter is mandatory when you add a firewall rule.<br>This parameter is optional when a firewall is removed. If this parameter is left empty, all [Direction](#direction) chains are cleared, and **domainName** and **appUid** must be also left empty.| 820 821## Direction 822 823Direction chains to which the rule applies. 824 825**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 826 827 828| Name | Value | Description | 829| ------ | ---- | -------- | 830| INPUT | 0 | Input chain.| 831| OUTPUT | 1 | Output chain.| 832| FORWARD<sup>15+</sup> | 2 | Forward chain. | 833 834## Action 835 836Enumerates the actions that can be taken for data packets. 837 838**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 839 840 841| Name | Value | Description | 842| ----- | ---- | ------------ | 843| ALLOW | 0 | Receive data packets.| 844| DENY | 1 | Discard data packets.| 845| REJECT<sup>15+</sup> | 2 | Reject data packets.| 846 847## Protocol 848 849Network protocol. 850 851**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 852 853 854| Name| Value | Description | 855| ---- | ---- | -------------- | 856| ALL | 0 | All network protocols.| 857| TCP | 1 | TCP. | 858| UDP | 2 | UDP. | 859| ICMP | 3 | ICMP.| 860