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