1# @ohos.enterprise.networkManager(网络管理)(系统接口) 2<!--Kit: MDM Kit--> 3<!--Subsystem: Customization--> 4<!--Owner: @huanleima--> 5<!--Designer: @liuzuming--> 6<!--Tester: @lpw_work--> 7<!--Adviser: @Brilliantry_Rui--> 8 9本模块提供设备网络管理能力,包括查询设备IP地址、MAC地址信息等。 10 11> **说明:** 12> 13> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 14> 15> 本模块接口仅可在Stage模型下使用。 16> 17> 本模块接口仅对[设备管理应用](../../mdm/mdm-kit-term.md#mdm应用设备管理应用)开放,需将[设备管理应用激活](js-apis-enterprise-adminManager-sys.md#adminmanagerenableadmin-2)后调用。 18> 19> 当前页面仅包含本模块的系统接口,其他公开接口参见。其他公开接口参见[@ohos.enterprise.networkManager](js-apis-enterprise-networkManager.md)。 20 21## 导入模块 22 23```ts 24import { networkManager } from '@kit.MDMKit'; 25``` 26 27## networkManager.getAllNetworkInterfaces 28 29getAllNetworkInterfaces(admin: Want, callback: AsyncCallback<Array<string>>): void 30 31获取所有激活的有线网络接口。使用callback异步回调。 32 33**需要权限:** ohos.permission.ENTERPRISE_GET_NETWORK_INFO 34 35**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 36 37**模型约束:** 此接口仅可在Stage模型下使用。 38 39**系统接口:** 此接口为系统接口。 40 41**参数:** 42 43| 参数名 | 类型 | 必填 | 说明 | 44| -------- | ---------------------------------------- | ---- | ------------------------------- | 45| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 46| callback | AsyncCallback<Array<string>> | 是 | 回调函数。当接口调用成功,err为null,data为网络接口名称数组,否则err为错误对象。 | 47 48**错误码**: 49 50以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 51 52| 错误码ID | 错误信息 | 53| ------- | ---------------------------------------------------------------------------- | 54| 9200001 | The application is not an administrator application of the device. | 55| 9200002 | The administrator application does not have permission to manage the device. | 56| 201 | Permission verification failed. The application does not have the permission required to call the API. | 57| 202 | Permission verification failed. A non-system application calls a system API. | 58| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 59 60**示例:** 61 62```ts 63import { networkManager } from '@kit.MDMKit'; 64import { Want } from '@kit.AbilityKit'; 65 66let wantTemp: Want = { 67 // 需根据实际情况进行替换 68 bundleName: 'com.example.myapplication', 69 abilityName: 'EntryAbility' 70}; 71 72networkManager.getAllNetworkInterfaces(wantTemp, (err, result) => { 73 if (err) { 74 console.error(`Failed to get all network interfaces. Code: ${err.code}, message: ${err.message}`); 75 return; 76 } 77 console.info(`Succeeded in getting all network interfaces, result : ${JSON.stringify(result)}`); 78}); 79``` 80 81## networkManager.getAllNetworkInterfaces 82 83getAllNetworkInterfaces(admin: Want): Promise<Array<string>> 84 85获取所有激活的有线网络接口。使用Promise异步回调。 86 87**需要权限:** ohos.permission.ENTERPRISE_GET_NETWORK_INFO 88 89**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 90 91**模型约束:** 此接口仅可在Stage模型下使用。 92 93**系统接口:** 此接口为系统接口。 94 95**参数:** 96 97| 参数名 | 类型 | 必填 | 说明 | 98| ------ | ------------------------------------------------------- | ---- | ---------------------- | 99| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 100 101**返回值:** 102 103| 类型 | 说明 | 104| --------------------- | ------------------------- | 105| Promise<Array<string>> | Promise结果,返回所有激活的有线网络接口名称数组。 | 106 107**错误码**: 108 109以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 110 111| 错误码ID | 错误信息 | 112| ------- | ---------------------------------------------------------------------------- | 113| 9200001 | The application is not an administrator application of the device. | 114| 9200002 | The administrator application does not have permission to manage the device. | 115| 201 | Permission verification failed. The application does not have the permission required to call the API. | 116| 202 | Permission verification failed. A non-system application calls a system API. | 117| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 118 119**示例:** 120 121```ts 122import { networkManager } from '@kit.MDMKit'; 123import { Want } from '@kit.AbilityKit'; 124import { BusinessError } from '@kit.BasicServicesKit'; 125 126let wantTemp: Want = { 127 // 需根据实际情况进行替换 128 bundleName: 'com.example.myapplication', 129 abilityName: 'EntryAbility' 130}; 131 132networkManager.getAllNetworkInterfaces(wantTemp).then((result) => { 133 console.info(`Succeeded in getting all network interfaces, result : ${JSON.stringify(result)}`); 134}).catch((err: BusinessError) => { 135 console.error(`Failed to get all network interfaces. Code: ${err.code}, message: ${err.message}`); 136}); 137``` 138 139## networkManager.getIpAddress 140 141getIpAddress(admin: Want, networkInterface: string, callback: AsyncCallback<string>): void 142 143根据网络接口获取设备IP地址。使用callback异步回调。 144 145**需要权限:** ohos.permission.ENTERPRISE_GET_NETWORK_INFO 146 147**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 148 149**模型约束:** 此接口仅可在Stage模型下使用。 150 151**系统接口:** 此接口为系统接口。 152 153**参数:** 154 155| 参数名 | 类型 | 必填 | 说明 | 156| -------- | ---------------------------------------- | ---- | ------------------------------- | 157| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 158| networkInterface | string | 是 | 指定网络接口。 | 159| callback | AsyncCallback<string> | 是 | 回调函数。当接口调用成功,err为null,data为IP地址,否则err为错误对象。 | 160 161**错误码**: 162 163以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 164 165| 错误码ID | 错误信息 | 166| ------- | ---------------------------------------------------------------------------- | 167| 9200001 | The application is not an administrator application of the device. | 168| 9200002 | The administrator application does not have permission to manage the device. | 169| 201 | Permission verification failed. The application does not have the permission required to call the API. | 170| 202 | Permission verification failed. A non-system application calls a system API. | 171| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 172 173**示例:** 174 175```ts 176import { networkManager } from '@kit.MDMKit'; 177import { Want } from '@kit.AbilityKit'; 178 179let wantTemp: Want = { 180 // 需根据实际情况进行替换 181 bundleName: 'com.example.myapplication', 182 abilityName: 'EntryAbility' 183}; 184 185// 参数需根据实际情况进行替换 186networkManager.getIpAddress(wantTemp, 'eth0', (err, result) => { 187 if (err) { 188 console.error(`Failed to get ip address. Code: ${err.code}, message: ${err.message}`); 189 return; 190 } 191 console.info(`Succeeded in getting ip address, result : ${result}`); 192}); 193``` 194 195## networkManager.getIpAddress 196 197getIpAddress(admin: Want, networkInterface: string): Promise<string> 198 199根据网络接口获取设备IP地址。使用Promise异步回调。 200 201**需要权限:** ohos.permission.ENTERPRISE_GET_NETWORK_INFO 202 203**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 204 205**模型约束:** 此接口仅可在Stage模型下使用。 206 207**系统接口:** 此接口为系统接口。 208 209**参数:** 210 211| 参数名 | 类型 | 必填 | 说明 | 212| ----- | ----------------------------------- | ---- | ------- | 213| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 214| networkInterface | string | 是 | 指定网络接口。 | 215 216**返回值:** 217 218| 类型 | 说明 | 219| --------------------- | ------------------------- | 220| Promise<string> | Promise结果,返回设备IP地址。 | 221 222**错误码**: 223 224以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 225 226| 错误码ID | 错误信息 | 227| ------- | ---------------------------------------------------------------------------- | 228| 9200001 | The application is not an administrator application of the device. | 229| 9200002 | The administrator application does not have permission to manage the device. | 230| 201 | Permission verification failed. The application does not have the permission required to call the API. | 231| 202 | Permission verification failed. A non-system application calls a system API. | 232| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 233 234**示例:** 235 236```ts 237import { networkManager } from '@kit.MDMKit'; 238import { Want } from '@kit.AbilityKit'; 239import { BusinessError } from '@kit.BasicServicesKit'; 240 241let wantTemp: Want = { 242 // 需根据实际情况进行替换 243 bundleName: 'com.example.myapplication', 244 abilityName: 'EntryAbility' 245}; 246 247// 参数需根据实际情况进行替换 248networkManager.getIpAddress(wantTemp, 'eth0').then((result) => { 249 console.info(`Succeeded in getting ip address, result : ${result}`); 250}).catch((err: BusinessError) => { 251 console.error(`Failed to get ip address. Code: ${err.code}, message: ${err.message}`); 252}); 253``` 254 255## networkManager.getMac 256 257getMac(admin: Want, networkInterface: string, callback: AsyncCallback<string>): void 258 259根据网络接口获取设备MAC地址。使用callback异步回调。 260 261**需要权限:** ohos.permission.ENTERPRISE_GET_NETWORK_INFO 262 263**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 264 265**模型约束:** 此接口仅可在Stage模型下使用。 266 267**系统接口:** 此接口为系统接口。 268 269**参数:** 270 271| 参数名 | 类型 | 必填 | 说明 | 272| -------- | ---------------------------------------- | ---- | ------------------------------- | 273| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 274| networkInterface | string | 是 | 指定网络接口。 | 275| callback | AsyncCallback<string> | 是 | 回调函数。当接口调用成功,err为null,data为设备MAC地址,否则err为错误对象。 | 276 277**错误码**: 278 279以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 280 281| 错误码ID | 错误信息 | 282| ------- | ---------------------------------------------------------------------------- | 283| 9200001 | The application is not an administrator application of the device. | 284| 9200002 | The administrator application does not have permission to manage the device. | 285| 201 | Permission verification failed. The application does not have the permission required to call the API. | 286| 202 | Permission verification failed. A non-system application calls a system API. | 287| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 288 289**示例:** 290 291```ts 292import { networkManager } from '@kit.MDMKit'; 293import { Want } from '@kit.AbilityKit'; 294 295let wantTemp: Want = { 296 // 需根据实际情况进行替换 297 bundleName: 'com.example.myapplication', 298 abilityName: 'EntryAbility' 299}; 300 301// 参数需根据实际情况进行替换 302networkManager.getMac(wantTemp, 'eth0', (err, result) => { 303 if (err) { 304 console.error(`Failed to get mac. Code: ${err.code}, message: ${err.message}`); 305 return; 306 } 307 console.info(`Succeeded in getting mac, result : ${result}`); 308}); 309``` 310 311## networkManager.getMac 312 313getMac(admin: Want, networkInterface: string): Promise\<string> 314 315根据网络接口获取设备MAC地址。使用Promise异步回调。 316 317**需要权限:** ohos.permission.ENTERPRISE_GET_NETWORK_INFO 318 319**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 320 321**模型约束:** 此接口仅可在Stage模型下使用。 322 323**系统接口:** 此接口为系统接口。 324 325**参数:** 326 327| 参数名 | 类型 | 必填 | 说明 | 328| ----- | ----------------------------------- | ---- | ------- | 329| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 330| networkInterface | string | 是 | 指定网络接口。 | 331 332**返回值:** 333 334| 类型 | 说明 | 335| --------------------- | ------------------------- | 336| Promise<string> | Promise结果,返回设备MAC地址。 | 337 338**错误码**: 339 340以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 341 342| 错误码ID | 错误信息 | 343| ------- | ---------------------------------------------------------------------------- | 344| 9200001 | The application is not an administrator application of the device. | 345| 9200002 | The administrator application does not have permission to manage the device. | 346| 201 | Permission verification failed. The application does not have the permission required to call the API. | 347| 202 | Permission verification failed. A non-system application calls a system API. | 348| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 349 350**示例:** 351 352```ts 353import { networkManager } from '@kit.MDMKit'; 354import { Want } from '@kit.AbilityKit'; 355import { BusinessError } from '@kit.BasicServicesKit'; 356 357let wantTemp: Want = { 358 // 需根据实际情况进行替换 359 bundleName: 'com.example.myapplication', 360 abilityName: 'EntryAbility' 361}; 362 363// 参数需根据实际情况进行替换 364networkManager.getMac(wantTemp, 'eth0').then((result) => { 365 console.info(`Succeeded in getting mac, result : ${result}`); 366}).catch((err: BusinessError) => { 367 console.error(`Failed to get mac. Code: ${err.code}, message: ${err.message}`); 368}); 369``` 370 371## networkManager.isNetworkInterfaceDisabled 372 373isNetworkInterfaceDisabled(admin: Want, networkInterface: string, callback: AsyncCallback<boolean>): void 374 375查询指定网络接口是否被禁用。使用callback异步回调。 376 377**需要权限:** ohos.permission.ENTERPRISE_GET_NETWORK_INFO 378 379**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 380 381**模型约束:** 此接口仅可在Stage模型下使用。 382 383**系统接口:** 此接口为系统接口。 384 385**参数:** 386 387| 参数名 | 类型 | 必填 | 说明 | 388| -------- | ---------------------------------------- | ---- | ------------------------------- | 389| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 390| networkInterface | string | 是 | 指定网络接口。 | 391| callback | AsyncCallback<boolean> | 是 | 回调函数。当接口调用成功,err为null,data为指定网络接口是否被禁用,true表示该网络接口被禁用,false表示该网络接口未被禁用,否则err为错误对象。 | 392 393**错误码**: 394 395以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 396 397| 错误码ID | 错误信息 | 398| ------- | ---------------------------------------------------------------------------- | 399| 9200001 | The application is not an administrator application of the device. | 400| 9200002 | The administrator application does not have permission to manage the device. | 401| 201 | Permission verification failed. The application does not have the permission required to call the API. | 402| 202 | Permission verification failed. A non-system application calls a system API. | 403| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 404 405**示例:** 406 407```ts 408import { networkManager } from '@kit.MDMKit'; 409import { Want } from '@kit.AbilityKit'; 410 411let wantTemp: Want = { 412 // 需根据实际情况进行替换 413 bundleName: 'com.example.myapplication', 414 abilityName: 'EntryAbility' 415}; 416 417// 参数需根据实际情况进行替换 418networkManager.isNetworkInterfaceDisabled(wantTemp, 'eth0', (err, result) => { 419 if (err) { 420 console.error(`Failed to query network interface is disabled or not. Code: ${err.code}, message: ${err.message}`); 421 return; 422 } 423 console.info(`Succeeded in querying network interface is disabled or not, result : ${result}`); 424}); 425``` 426 427## networkManager.isNetworkInterfaceDisabled 428 429isNetworkInterfaceDisabled(admin: Want, networkInterface: string): Promise<boolean> 430 431查询指定网络接口是否被禁用。使用Promise异步回调。 432 433**需要权限:** ohos.permission.ENTERPRISE_GET_NETWORK_INFO 434 435**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 436 437**模型约束:** 此接口仅可在Stage模型下使用。 438 439**系统接口:** 此接口为系统接口。 440 441**参数:** 442 443| 参数名 | 类型 | 必填 | 说明 | 444| ----- | ----------------------------------- | ---- | ------- | 445| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 446| networkInterface | string | 是 | 指定网络接口。 | 447 448**返回值:** 449 450| 类型 | 说明 | 451| --------------------- | ------------------------- | 452| Promise<boolean> | Promise结果,返回指定网络接口是否被禁用,true表示该网络接口被禁用,false表示该网络接口未被禁用。 | 453 454**错误码**: 455 456以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 457 458| 错误码ID | 错误信息 | 459| ------- | ---------------------------------------------------------------------------- | 460| 9200001 | The application is not an administrator application of the device. | 461| 9200002 | The administrator application does not have permission to manage the device. | 462| 201 | Permission verification failed. The application does not have the permission required to call the API. | 463| 202 | Permission verification failed. A non-system application calls a system API. | 464| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 465 466**示例:** 467 468```ts 469import { networkManager } from '@kit.MDMKit'; 470import { Want } from '@kit.AbilityKit'; 471import { BusinessError } from '@kit.BasicServicesKit'; 472 473let wantTemp: Want = { 474 // 需根据实际情况进行替换 475 bundleName: 'com.example.myapplication', 476 abilityName: 'EntryAbility' 477}; 478 479// 参数需根据实际情况进行替换 480networkManager.isNetworkInterfaceDisabled(wantTemp, 'eth0').then((result) => { 481 console.info(`Succeeded in querying network interface is disabled or not, result : ${result}`); 482}).catch((err: BusinessError) => { 483 console.error(`Failed to query network interface is disabled or not. Code: ${err.code}, message: ${err.message}`); 484}); 485``` 486 487## networkManager.setNetworkInterfaceDisabled 488 489setNetworkInterfaceDisabled(admin: Want, networkInterface: string, isDisabled: boolean, callback: AsyncCallback<void>): void 490 491禁止设备使用指定网络。使用callback异步回调。 492 493**需要权限:** ohos.permission.ENTERPRISE_SET_NETWORK 494 495**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 496 497**模型约束:** 此接口仅可在Stage模型下使用。 498 499**系统接口:** 此接口为系统接口。 500 501**参数:** 502 503| 参数名 | 类型 | 必填 | 说明 | 504| -------- | ---------------------------------------- | ---- | ------------------------------- | 505| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 506| networkInterface | string | 是 | 指定网络接口。 | 507| isDisabled | boolean | 是 | true表示禁用该网络接口,false表示开启该网络接口。 | 508| callback | AsyncCallback<void> | 是 | 回调函数。当接口调用成功,err为null,否则err为错误对象。 | 509 510**错误码**: 511 512以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 513 514| 错误码ID | 错误信息 | 515| ------- | ---------------------------------------------------------------------------- | 516| 9200001 | The application is not an administrator application of the device. | 517| 9200002 | The administrator application does not have permission to manage the device. | 518| 201 | Permission verification failed. The application does not have the permission required to call the API. | 519| 202 | Permission verification failed. A non-system application calls a system API. | 520| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 521 522**示例:** 523 524```ts 525import { networkManager } from '@kit.MDMKit'; 526import { Want } from '@kit.AbilityKit'; 527 528let wantTemp: Want = { 529 // 需根据实际情况进行替换 530 bundleName: 'com.example.myapplication', 531 abilityName: 'EntryAbility' 532}; 533 534// 参数需根据实际情况进行替换 535networkManager.setNetworkInterfaceDisabled(wantTemp, 'eth0', true, (err) => { 536 if (err) { 537 console.error(`Failed to set network interface disabled. Code: ${err.code}, message: ${err.message}`); 538 return; 539 } 540 console.info(`Succeeded in setting network interface disabled`); 541}); 542``` 543 544## networkManager.setNetworkInterfaceDisabled 545 546setNetworkInterfaceDisabled(admin: Want, networkInterface: string, isDisabled: boolean): Promise<void> 547 548禁止设备使用指定网络。使用Promise异步回调。 549 550**需要权限:** ohos.permission.ENTERPRISE_SET_NETWORK 551 552**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 553 554**模型约束:** 此接口仅可在Stage模型下使用。 555 556**系统接口:** 此接口为系统接口。 557 558**参数:** 559 560| 参数名 | 类型 | 必填 | 说明 | 561| ----- | ----------------------------------- | ---- | ------- | 562| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 563| networkInterface | string | 是 | 指定网络接口。 | 564| isDisabled | boolean | 是 | true表示禁用该网络接口,false表示开启该网络接口。 | 565 566**返回值:** 567 568| 类型 | 说明 | 569| --------------------- | ------------------------- | 570| Promise<void> | 无返回结果的Promise对象。当禁用网络接口失败时抛出错误对象。 | 571 572**错误码**: 573 574以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 575 576| 错误码ID | 错误信息 | 577| ------- | ---------------------------------------------------------------------------- | 578| 9200001 | The application is not an administrator application of the device. | 579| 9200002 | The administrator application does not have permission to manage the device. | 580| 201 | Permission verification failed. The application does not have the permission required to call the API. | 581| 202 | Permission verification failed. A non-system application calls a system API. | 582| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 583 584**示例:** 585 586```ts 587import { networkManager } from '@kit.MDMKit'; 588import { Want } from '@kit.AbilityKit'; 589import { BusinessError } from '@kit.BasicServicesKit'; 590 591let wantTemp: Want = { 592 // 需根据实际情况进行替换 593 bundleName: 'com.example.myapplication', 594 abilityName: 'EntryAbility' 595}; 596 597// 参数需根据实际情况进行替换 598networkManager.setNetworkInterfaceDisabled(wantTemp, 'eth0', true).then(() => { 599 console.info(`Succeeded in setting network interface disabled`); 600}).catch((err: BusinessError) => { 601 console.error(`Failed to set network interface disabled. Code: ${err.code}, message: ${err.message}`); 602}); 603``` 604 605## networkManager.setGlobalProxy 606 607setGlobalProxy(admin: Want, httpProxy: connection.HttpProxy, callback: AsyncCallback\<void>): void 608 609设置网络全局代理,使用callback异步回调。 610 611**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK 612 613**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 614 615**模型约束:** 此接口仅可在Stage模型下使用。 616 617**系统接口:** 此接口为系统接口。 618 619**参数:** 620 621| 参数名 | 类型 | 必填 | 说明 | 622| -------- | ---------------------------------------- | ---- | ------------------------------- | 623| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 624| httpProxy | [connection.HttpProxy](../apis-network-kit/js-apis-net-connection.md#httpproxy10) | 是 | 网络全局Http代理配置信息。 | 625| callback | AsyncCallback<void> | 是 | 回调函数。当接口调用成功,err为null,否则err为错误对象。 | 626 627**错误码**: 628 629以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 630 631| 错误码ID | 错误信息 | 632| ------- | ---------------------------------------------------------------------------- | 633| 9200001 | The application is not an administrator application of the device. | 634| 9200002 | The administrator application does not have permission to manage the device. | 635| 201 | Permission verification failed. The application does not have the permission required to call the API. | 636| 202 | Permission verification failed. A non-system application calls a system API. | 637| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 638 639**示例:** 640 641```ts 642import { networkManager } from '@kit.MDMKit'; 643import { Want } from '@kit.AbilityKit'; 644import { connection } from '@kit.NetworkKit'; 645 646let wantTemp: Want = { 647 // 需根据实际情况进行替换 648 bundleName: 'com.example.myapplication', 649 abilityName: 'EntryAbility' 650}; 651 652// 参数需根据实际情况进行替换 653let exclusionStr: string = "192.168,baidu.com" 654let exclusionArray: Array<string> = exclusionStr.split(','); 655let httpProxy: connection.HttpProxy = { 656 host: "192.168.xx.xxx", 657 port: 8080, 658 exclusionList: exclusionArray 659}; 660 661networkManager.setGlobalProxy(wantTemp, httpProxy, (err) => { 662 if (err) { 663 console.error(`Failed to set network global proxy. Code: ${err.code}, message: ${err.message}`); 664 return; 665 } 666 console.info(`Succeeded in setting network global proxy`); 667}); 668``` 669 670## networkManager.setGlobalProxy 671 672setGlobalProxy(admin: Want, httpProxy: connection.HttpProxy): Promise\<void> 673 674设置网络全局代理,使用Promise异步回调。 675 676**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK 677 678**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 679 680**模型约束:** 此接口仅可在Stage模型下使用。 681 682**系统接口:** 此接口为系统接口。 683 684**参数:** 685 686| 参数名 | 类型 | 必填 | 说明 | 687| ----- | ----------------------------------- | ---- | ------- | 688| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 689| httpProxy | [connection.HttpProxy](../apis-network-kit/js-apis-net-connection.md#httpproxy10) | 是 | 网络全局Http代理配置信息。 | 690 691**返回值:** 692 693| 类型 | 说明 | 694| --------------------- | ------------------------- | 695| Promise<void> | 无返回结果的Promise对象。当设置网络全局代理失败时抛出错误对象。 | 696 697**错误码**: 698 699以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 700 701| 错误码ID | 错误信息 | 702| ------- | ---------------------------------------------------------------------------- | 703| 9200001 | The application is not an administrator application of the device. | 704| 9200002 | The administrator application does not have permission to manage the device. | 705| 201 | Permission verification failed. The application does not have the permission required to call the API. | 706| 202 | Permission verification failed. A non-system application calls a system API. | 707| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 708 709**示例:** 710 711```ts 712import { networkManager } from '@kit.MDMKit'; 713import { Want } from '@kit.AbilityKit'; 714import { BusinessError } from '@kit.BasicServicesKit'; 715import { connection } from '@kit.NetworkKit'; 716 717let wantTemp: Want = { 718 // 需根据实际情况进行替换 719 bundleName: 'com.example.myapplication', 720 abilityName: 'EntryAbility' 721}; 722 723// 需根据实际情况进行替换 724let exclusionStr: string = "192.168,baidu.com" 725let exclusionArray: Array<string> = exclusionStr.split(','); 726let httpProxy: connection.HttpProxy = { 727 host: "192.168.xx.xxx", 728 port: 8080, 729 exclusionList: exclusionArray 730}; 731 732networkManager.setGlobalProxy(wantTemp, httpProxy).then(() => { 733 console.info(`Succeeded in setting network global proxy`); 734}).catch((err: BusinessError) => { 735 console.error(`Failed to set network global proxy. Code: ${err.code}, message: ${err.message}`); 736}); 737``` 738 739## networkManager.getGlobalProxy 740 741getGlobalProxy(admin: Want, callback: AsyncCallback\<connection.HttpProxy>): void 742 743获取网络全局代理,使用callback异步回调。 744 745**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK 746 747**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 748 749**模型约束:** 此接口仅可在Stage模型下使用。 750 751**系统接口:** 此接口为系统接口。 752 753**参数:** 754 755| 参数名 | 类型 | 必填 | 说明 | 756| -------- | ---------------------------------------- | ---- | ------------------------------- | 757| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 758| callback | AsyncCallback<[connection.HttpProxy](../apis-network-kit/js-apis-net-connection.md#httpproxy10)> | 是 | 回调函数。当接口调用成功,err为null,否则err为错误对象。 | 759 760**错误码**: 761 762以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 763 764| 错误码ID | 错误信息 | 765| ------- | ---------------------------------------------------------------------------- | 766| 9200001 | The application is not an administrator application of the device. | 767| 9200002 | The administrator application does not have permission to manage the device. | 768| 201 | Permission verification failed. The application does not have the permission required to call the API. | 769| 202 | Permission verification failed. A non-system application calls a system API. | 770| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 771 772**示例:** 773 774```ts 775import { networkManager } from '@kit.MDMKit'; 776import { Want } from '@kit.AbilityKit'; 777 778let wantTemp: Want = { 779 // 需根据实际情况进行替换 780 bundleName: 'com.example.myapplication', 781 abilityName: 'EntryAbility' 782}; 783 784networkManager.getGlobalProxy(wantTemp, (err, result) => { 785 if (err) { 786 console.error(`Failed to get network global proxy. Code: ${err.code}, message: ${err.message}`); 787 return; 788 } 789 console.info(`Succeeded in getting network global proxy, result : ${JSON.stringify(result)}`); 790}); 791``` 792 793## networkManager.getGlobalProxy 794 795getGlobalProxy(admin: Want): Promise\<connection.HttpProxy> 796 797获取网络全局代理,使用Promise异步回调。 798 799**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK 800 801**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 802 803**模型约束:** 此接口仅可在Stage模型下使用。 804 805**系统接口:** 此接口为系统接口。 806 807**参数:** 808 809| 参数名 | 类型 | 必填 | 说明 | 810| ------ | ------------------------------------------------------- | ---- | ---------------------- | 811| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 812 813**返回值:** 814 815| 类型 | 说明 | 816| --------------------- | ------------------------- | 817| Promise<[connection.HttpProxy](../apis-network-kit/js-apis-net-connection.md#httpproxy10)> | Promise对象,返回网络全局Http代理配置信息。 | 818 819**错误码**: 820 821以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 822 823| 错误码ID | 错误信息 | 824| ------- | ---------------------------------------------------------------------------- | 825| 9200001 | The application is not an administrator application of the device. | 826| 9200002 | The administrator application does not have permission to manage the device. | 827| 201 | Permission verification failed. The application does not have the permission required to call the API. | 828| 202 | Permission verification failed. A non-system application calls a system API. | 829| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 830 831**示例:** 832 833```ts 834import { networkManager } from '@kit.MDMKit'; 835import { Want } from '@kit.AbilityKit'; 836import { BusinessError } from '@kit.BasicServicesKit'; 837 838let wantTemp: Want = { 839 // 需根据实际情况进行替换 840 bundleName: 'com.example.myapplication', 841 abilityName: 'EntryAbility' 842}; 843 844networkManager.getGlobalProxy(wantTemp).then(() => { 845 console.info(`Succeeded in getting network global proxy`); 846}).catch((err: BusinessError) => { 847 console.error(`Failed to get network global proxy. Code: ${err.code}, message: ${err.message}`); 848}); 849``` 850 851## networkManager.addIptablesFilterRule 852 853addIptablesFilterRule(admin: Want, filterRule: AddFilterRule, callback: AsyncCallback\<void>): void 854 855为设备添加网络包过滤规则,仅支持IPv4。使用callback异步回调。 856 857**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK 858 859**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 860 861**模型约束:** 此接口仅可在Stage模型下使用。 862 863**系统接口:** 此接口为系统接口。 864 865**参数:** 866 867| 参数名 | 类型 | 必填 | 说明 | 868| -------- | ---------------------------------------- | ---- | ------------------------------- | 869| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 870| filterRule | [AddFilterRule](#addfilterrule) | 是 | 添加网络包过滤规则。 | 871| callback | AsyncCallback<void> | 是 | 回调函数。当接口调用成功,err为null,否则err为错误对象。 | 872 873**错误码**: 874 875以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 876 877| 错误码ID | 错误信息 | 878| ------- | ---------------------------------------------------------------------------- | 879| 9200001 | The application is not an administrator application of the device. | 880| 9200002 | The administrator application does not have permission to manage the device. | 881| 201 | Permission verification failed. The application does not have the permission required to call the API. | 882| 202 | Permission verification failed. A non-system application calls a system API. | 883| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 884 885**示例:** 886 887```ts 888import { networkManager } from '@kit.MDMKit'; 889import { Want } from '@kit.AbilityKit'; 890 891let wantTemp: Want = { 892 // 需根据实际情况进行替换 893 bundleName: 'com.example.myapplication', 894 abilityName: 'EntryAbility' 895}; 896let filterRule: networkManager.AddFilterRule = { 897 // 需根据实际情况进行替换 898 "ruleNo": 1, 899 "srcAddr": "192.168.1.1-192.168.255.255", 900 "destAddr": "10.1.1.1", 901 "srcPort": "8080", 902 "destPort": "8080", 903 "uid": "9696", 904 "method": networkManager.AddMethod.APPEND, 905 "direction": networkManager.Direction.OUTPUT, 906 "action": networkManager.Action.DENY, 907 "protocol": networkManager.Protocol.UDP 908}; 909 910networkManager.addIptablesFilterRule(wantTemp, filterRule, (err) => { 911 if (err) { 912 console.error(`Failed to set iptables filter rule. Code: ${err.code}, message: ${err.message}`); 913 return; 914 } 915 console.info(`Succeeded in setting iptables filter rule`); 916}); 917``` 918 919## networkManager.addIptablesFilterRule 920 921addIptablesFilterRule(admin: Want, filterRule: AddFilterRule): Promise\<void> 922 923为设备添加网络包过滤规则,仅支持IPv4。使用Promise异步回调。 924 925**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK 926 927**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 928 929**模型约束:** 此接口仅可在Stage模型下使用。 930 931**系统接口:** 此接口为系统接口。 932 933**参数:** 934 935| 参数名 | 类型 | 必填 | 说明 | 936| ----- | ----------------------------------- | ---- | ------- | 937| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 938| filterRule | [AddFilterRule](#addfilterrule) | 是 | 添加网络包过滤规则。 | 939 940**返回值:** 941 942| 类型 | 说明 | 943| --------------------- | ------------------------- | 944| Promise<void> | 无返回结果的Promise对象。当添加网络包过滤规则失败时抛出错误对象。 | 945 946**错误码**: 947 948以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 949 950| 错误码ID | 错误信息 | 951| ------- | ---------------------------------------------------------------------------- | 952| 9200001 | The application is not an administrator application of the device. | 953| 9200002 | The administrator application does not have permission to manage the device. | 954| 201 | Permission verification failed. The application does not have the permission required to call the API. | 955| 202 | Permission verification failed. A non-system application calls a system API. | 956| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 957 958**示例:** 959 960```ts 961import { networkManager } from '@kit.MDMKit'; 962import { Want } from '@kit.AbilityKit'; 963import { BusinessError } from '@kit.BasicServicesKit'; 964 965let wantTemp: Want = { 966 // 需根据实际情况进行替换 967 bundleName: 'com.example.myapplication', 968 abilityName: 'EntryAbility' 969}; 970let filterRule: networkManager.AddFilterRule = { 971 // 需根据实际情况进行替换 972 "ruleNo": 1, 973 "srcAddr": "192.168.1.1-192.168.255.255", 974 "destAddr": "10.1.1.1", 975 "srcPort": "8080", 976 "destPort": "8080", 977 "uid": "9696", 978 "method": networkManager.AddMethod.APPEND, 979 "direction": networkManager.Direction.OUTPUT, 980 "action": networkManager.Action.DENY, 981 "protocol": networkManager.Protocol.UDP 982}; 983 984networkManager.addIptablesFilterRule(wantTemp, filterRule).then(() => { 985 console.info(`Succeeded in setting iptables filter rule`); 986}).catch((err: BusinessError) => { 987 console.error(`Failed to set iptables filter rule. Code: ${err.code}, message: ${err.message}`); 988}); 989``` 990 991## networkManager.removeIptablesFilterRule 992 993removeIptablesFilterRule(admin: Want, filterRule: RemoveFilterRule, callback: AsyncCallback\<void>): void 994 995移除网络包过滤规则,仅支持IPv4。使用callback异步回调。 996 997**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK 998 999**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1000 1001**模型约束:** 此接口仅可在Stage模型下使用。 1002 1003**系统接口:** 此接口为系统接口。 1004 1005**参数:** 1006 1007| 参数名 | 类型 | 必填 | 说明 | 1008| -------- | ---------------------------------------- | ---- | ------------------------------- | 1009| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 1010| filterRule | [RemoveFilterRule](#removefilterrule) | 是 | 移除网络包过滤规则。 | 1011| callback | AsyncCallback<void> | 是 | 回调函数。当接口调用成功,err为null,否则err为错误对象。 | 1012 1013**错误码**: 1014 1015以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 1016 1017| 错误码ID | 错误信息 | 1018| ------- | ---------------------------------------------------------------------------- | 1019| 9200001 | The application is not an administrator application of the device. | 1020| 9200002 | The administrator application does not have permission to manage the device. | 1021| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1022| 202 | Permission verification failed. A non-system application calls a system API. | 1023| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1024 1025**示例:** 1026 1027```ts 1028import { networkManager } from '@kit.MDMKit'; 1029import { Want } from '@kit.AbilityKit'; 1030 1031let wantTemp: Want = { 1032 // 需根据实际情况进行替换 1033 bundleName: 'com.example.myapplication', 1034 abilityName: 'EntryAbility' 1035}; 1036let filterRule: networkManager.RemoveFilterRule = { 1037 // 需根据实际情况进行替换 1038 "srcAddr": "192.168.1.1-192.168.255.255", 1039 "destAddr": "10.1.1.1", 1040 "srcPort": "8080", 1041 "destPort": "8080", 1042 "uid": "9696", 1043 "direction": networkManager.Direction.OUTPUT, 1044 "action": networkManager.Action.DENY, 1045 "protocol": networkManager.Protocol.UDP 1046}; 1047 1048networkManager.removeIptablesFilterRule(wantTemp, filterRule, (err) => { 1049 if (err) { 1050 console.error(`Failed to remove iptables filter rule. Code: ${err.code}, message: ${err.message}`); 1051 return; 1052 } 1053 console.info(`Succeeded in removing iptables filter rule`); 1054}); 1055``` 1056 1057## networkManager.removeIptablesFilterRule 1058 1059removeIptablesFilterRule(admin: Want, filterRule: RemoveFilterRule): Promise\<void> 1060 1061移除网络包过滤规则,仅支持IPv4。使用Promise异步回调。 1062 1063**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK 1064 1065**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1066 1067**模型约束:** 此接口仅可在Stage模型下使用。 1068 1069**系统接口:** 此接口为系统接口。 1070 1071**参数:** 1072 1073| 参数名 | 类型 | 必填 | 说明 | 1074| ----- | ----------------------------------- | ---- | ------- | 1075| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 1076| filterRule | [RemoveFilterRule](#removefilterrule) | 是 | 移除网络包过滤规则。 | 1077 1078**返回值:** 1079 1080| 类型 | 说明 | 1081| --------------------- | ------------------------- | 1082| Promise<void> | 无返回结果的Promise对象。当移除网络包过滤规则失败时抛出错误对象。 | 1083 1084**错误码**: 1085 1086以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 1087 1088| 错误码ID | 错误信息 | 1089| ------- | ---------------------------------------------------------------------------- | 1090| 9200001 | The application is not an administrator application of the device. | 1091| 9200002 | The administrator application does not have permission to manage the device. | 1092| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1093| 202 | Permission verification failed. A non-system application calls a system API. | 1094| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1095 1096**示例:** 1097 1098```ts 1099import { networkManager } from '@kit.MDMKit'; 1100import { Want } from '@kit.AbilityKit'; 1101import { BusinessError } from '@kit.BasicServicesKit'; 1102 1103let wantTemp: Want = { 1104 // 需根据实际情况进行替换 1105 bundleName: 'com.example.myapplication', 1106 abilityName: 'EntryAbility' 1107}; 1108let filterRule: networkManager.RemoveFilterRule = { 1109 // 需根据实际情况进行替换 1110 "srcAddr": "192.168.1.1-192.168.255.255", 1111 "destAddr": "10.1.1.1", 1112 "srcPort": "8080", 1113 "destPort": "8080", 1114 "uid": "9696", 1115 "direction": networkManager.Direction.OUTPUT, 1116 "action": networkManager.Action.DENY, 1117 "protocol": networkManager.Protocol.UDP 1118}; 1119 1120networkManager.removeIptablesFilterRule(wantTemp, filterRule).then(() => { 1121 console.info(`Succeeded in removing iptables filter rule`); 1122}).catch((err: BusinessError) => { 1123 console.error(`Failed to remove iptables filter rule. Code: ${err.code}, message: ${err.message}`); 1124}); 1125``` 1126 1127## networkManager.listIptablesFilterRules 1128 1129listIptablesFilterRules(admin: Want, callback: AsyncCallback\<string>): void 1130 1131获取网络包过滤规则,仅支持IPv4。使用callback异步回调。 1132 1133**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK 1134 1135**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1136 1137**模型约束:** 此接口仅可在Stage模型下使用。 1138 1139**系统接口:** 此接口为系统接口。 1140 1141**参数:** 1142 1143| 参数名 | 类型 | 必填 | 说明 | 1144| -------- | ---------------------------------------- | ---- | ------------------------------- | 1145| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 1146| callback | AsyncCallback<string> | 是 | 回调函数。当接口调用成功,err为null,否则err为错误对象。 | 1147 1148**错误码**: 1149 1150以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 1151 1152| 错误码ID | 错误信息 | 1153| ------- | ---------------------------------------------------------------------------- | 1154| 9200001 | The application is not an administrator application of the device. | 1155| 9200002 | The administrator application does not have permission to manage the device. | 1156| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1157| 202 | Permission verification failed. A non-system application calls a system API. | 1158| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1159 1160**示例:** 1161 1162```ts 1163import { networkManager } from '@kit.MDMKit'; 1164import { Want } from '@kit.AbilityKit'; 1165 1166let wantTemp: Want = { 1167 // 需根据实际情况进行替换 1168 bundleName: 'com.example.myapplication', 1169 abilityName: 'EntryAbility' 1170}; 1171 1172networkManager.listIptablesFilterRules(wantTemp, (err, result) => { 1173 if (err) { 1174 console.error(`Failed to get iptables filter rule. Code: ${err.code}, message: ${err.message}`); 1175 return; 1176 } 1177 console.info(`Succeeded in getting iptables filter rule, result : ${result}`); 1178}); 1179``` 1180 1181## networkManager.listIptablesFilterRules 1182 1183listIptablesFilterRules(admin: Want): Promise\<string> 1184 1185获取网络包过滤规则,仅支持IPv4。使用Promise异步回调。 1186 1187**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK 1188 1189**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1190 1191**模型约束:** 此接口仅可在Stage模型下使用。 1192 1193**系统接口:** 此接口为系统接口。 1194 1195**参数:** 1196 1197| 参数名 | 类型 | 必填 | 说明 | 1198| ------ | ------------------------------------------------------- | ---- | ---------------------- | 1199| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 1200 1201**返回值:** 1202 1203| 类型 | 说明 | 1204| --------------------- | ------------------------- | 1205| Promise<string> | Promise对象,返回网络包过滤规则。 | 1206 1207**错误码**: 1208 1209以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 1210 1211| 错误码ID | 错误信息 | 1212| ------- | ---------------------------------------------------------------------------- | 1213| 9200001 | The application is not an administrator application of the device. | 1214| 9200002 | The administrator application does not have permission to manage the device. | 1215| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1216| 202 | Permission verification failed. A non-system application calls a system API. | 1217| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1218 1219**示例:** 1220 1221```ts 1222import { networkManager } from '@kit.MDMKit'; 1223import { Want } from '@kit.AbilityKit'; 1224import { BusinessError } from '@kit.BasicServicesKit'; 1225 1226let wantTemp: Want = { 1227 // 需根据实际情况进行替换 1228 bundleName: 'com.example.myapplication', 1229 abilityName: 'EntryAbility' 1230}; 1231 1232networkManager.listIptablesFilterRules(wantTemp).then((result) => { 1233 console.info(`Succeeded in getting iptables filter rule, result: ${result}`); 1234}).catch((err: BusinessError) => { 1235 console.error(`Failed to remove iptables filter rule. Code: ${err.code}, message: ${err.message}`); 1236}); 1237``` 1238 1239## AddFilterRule 1240 1241添加网络包过滤规则。 1242 1243**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1244 1245**系统接口:** 此接口为系统接口。 1246 1247| 名称 | 类型 | 只读 | 可选 | 说明 | 1248| ----------- | --------| ---- | ---- | ------------------------------- | 1249| ruleNo | number | 否 | 是 | 规则序号。 | 1250| srcAddr | string | 否 | 是 | ip源地址。 | 1251| destAddr | string | 否 | 是 | ip目标地址。 | 1252| srcPort | string | 否 | 是 | ip源端口。 | 1253| destPort | string | 否 | 是 | ip目标端口。 | 1254| uid | string | 否 | 是 | 应用uid。 | 1255| method | [AddMethod](#addmethod) | 否 | 否 | 添加策略。 | 1256| direction | [Direction](js-apis-enterprise-networkManager.md#direction) | 否 | 否 | 规则链。 | 1257| action | [Action](js-apis-enterprise-networkManager.md#action) | 否 | 否 | 接收或者丢弃数据包。 | 1258| protocol | [Protocol](js-apis-enterprise-networkManager.md#protocol) | 否 | 是 |网络协议。 | 1259 1260## RemoveFilterRule 1261 1262移除网络包过滤规则。 1263 1264**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1265 1266**系统接口:** 此接口为系统接口。 1267 1268| 名称 | 类型 | 只读 | 可选 | 说明 | 1269| ----------- | --------| ---- | ---- | ------------------------------ | 1270| srcAddr | string | 否 | 是 | ip源地址。 | 1271| destAddr | string | 否 | 是 | ip目标地址。 | 1272| srcPort | string | 否 | 是 | ip源端口。 | 1273| destPort | string | 否 | 是 | ip目标端口。 | 1274| uid | string | 否 | 是 | 应用uid。 | 1275| direction | [Direction](js-apis-enterprise-networkManager.md#direction) | 否 | 否 | 规则链。 | 1276| action | [Action](js-apis-enterprise-networkManager.md#action) | 否 | 是 | 接收或者丢弃数据包。 | 1277| protocol | [Protocol](js-apis-enterprise-networkManager.md#protocol) | 否 | 是 | 网络协议。 | 1278 1279## AddMethod 1280 1281添加网络包方法。 1282 1283**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1284 1285**系统接口:** 此接口为系统接口。 1286 1287| 名称 | 值 | 说明 | 1288| -------- | -------- | -------- | 1289| APPEND | 0 | 追加。 | 1290| INSERT | 1 | 插入。 | 1291