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