1e41f4b71Sopenharmony_ci# @ohos.enterprise.networkManager(网络管理)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci本模块提供设备网络管理能力,包括查询设备IP地址、MAC地址信息等。
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **说明:**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 12开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8e41f4b71Sopenharmony_ci>
9e41f4b71Sopenharmony_ci> 本模块接口仅可在Stage模型下使用。
10e41f4b71Sopenharmony_ci>
11e41f4b71Sopenharmony_ci> 本模块接口仅对[设备管理应用](../../mdm/mdm-kit-guide.md#功能介绍)开放,需将设备管理应用激活后调用,实现相应功能。
12e41f4b71Sopenharmony_ci>
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci## 导入模块
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci```ts
17e41f4b71Sopenharmony_ciimport { networkManager } from '@kit.MDMKit';
18e41f4b71Sopenharmony_ci```
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci## networkManager.getAllNetworkInterfacesSync
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_cigetAllNetworkInterfacesSync(admin: Want): Array<string>
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci指定设备管理应用获取所有激活的网络接口。
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci**参数:**
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci| 参数名 | 类型                                                    | 必填 | 说明           |
34e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------- | ---- | -------------- |
35e41f4b71Sopenharmony_ci| admin  | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 设备管理应用。 |
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci**返回值:**
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci| 类型                | 说明                   |
40e41f4b71Sopenharmony_ci| ------------------- | ---------------------- |
41e41f4b71Sopenharmony_ci| Array<string> | 返回网络接口名称数组。 |
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci**错误码**:
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
48e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
49e41f4b71Sopenharmony_ci| 9200001  | The application is not an administrator application of the device. |
50e41f4b71Sopenharmony_ci| 9200002  | The administrator application does not have permission to manage the device. |
51e41f4b71Sopenharmony_ci| 201      | Permission verification failed. The application does not have the permission required to call the API. |
52e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci**示例:**
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ci```ts
57e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
58e41f4b71Sopenharmony_cilet wantTemp: Want = {
59e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
60e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
61e41f4b71Sopenharmony_ci};
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_citry {
64e41f4b71Sopenharmony_ci  let result: Array<string> = networkManager.getAllNetworkInterfacesSync(wantTemp);
65e41f4b71Sopenharmony_ci  console.info(`Succeeded in getting all network interfaces, result : ${JSON.stringify(result)}`);
66e41f4b71Sopenharmony_ci} catch (err) {
67e41f4b71Sopenharmony_ci  console.error(`Failed to get all network interfaces. Code: ${err.code}, message: ${err.message}`);
68e41f4b71Sopenharmony_ci}
69e41f4b71Sopenharmony_ci```
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci## networkManager.getIpAddressSync
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_cigetIpAddressSync(admin: Want, networkInterface: string): string
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci指定设备管理应用根据网络接口获取设备IP地址。
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci**参数:**
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci| 参数名           | 类型                                                    | 必填 | 说明           |
85e41f4b71Sopenharmony_ci| ---------------- | ------------------------------------------------------- | ---- | -------------- |
86e41f4b71Sopenharmony_ci| admin            | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 设备管理应用。 |
87e41f4b71Sopenharmony_ci| networkInterface | string                                                  | 是   | 指定网络接口。 |
88e41f4b71Sopenharmony_ci
89e41f4b71Sopenharmony_ci**返回值:**
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci| 类型   | 说明             |
92e41f4b71Sopenharmony_ci| ------ | ---------------- |
93e41f4b71Sopenharmony_ci| string | 返回设备IP地址。 |
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ci**错误码**:
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
98e41f4b71Sopenharmony_ci
99e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
100e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
101e41f4b71Sopenharmony_ci| 9200001  | The application is not an administrator application of the device. |
102e41f4b71Sopenharmony_ci| 9200002  | The administrator application does not have permission to manage the device. |
103e41f4b71Sopenharmony_ci| 201      | Permission verification failed. The application does not have the permission required to call the API. |
104e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci**示例:**
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ci```ts
109e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
110e41f4b71Sopenharmony_cilet wantTemp: Want = {
111e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
112e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
113e41f4b71Sopenharmony_ci};
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_citry {
116e41f4b71Sopenharmony_ci  let result: string = networkManager.getIpAddressSync(wantTemp, 'eth0');
117e41f4b71Sopenharmony_ci  console.info(`Succeeded in getting ip address, result : ${result}`);
118e41f4b71Sopenharmony_ci} catch (err) {
119e41f4b71Sopenharmony_ci  console.error(`Failed to get ip address. Code: ${err.code}, message: ${err.message}`);
120e41f4b71Sopenharmony_ci}
121e41f4b71Sopenharmony_ci```
122e41f4b71Sopenharmony_ci
123e41f4b71Sopenharmony_ci## networkManager.getMacSync
124e41f4b71Sopenharmony_ci
125e41f4b71Sopenharmony_cigetMacSync(admin: Want, networkInterface: string): string
126e41f4b71Sopenharmony_ci
127e41f4b71Sopenharmony_ci指定设备管理应用根据网络接口获取设备MAC地址。
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
132e41f4b71Sopenharmony_ci
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_ci**参数:**
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_ci| 参数名           | 类型                                                    | 必填 | 说明           |
137e41f4b71Sopenharmony_ci| ---------------- | ------------------------------------------------------- | ---- | -------------- |
138e41f4b71Sopenharmony_ci| admin            | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 设备管理应用。 |
139e41f4b71Sopenharmony_ci| networkInterface | string                                                  | 是   | 指定网络接口。 |
140e41f4b71Sopenharmony_ci
141e41f4b71Sopenharmony_ci**返回值:**
142e41f4b71Sopenharmony_ci
143e41f4b71Sopenharmony_ci| 类型   | 说明              |
144e41f4b71Sopenharmony_ci| ------ | ----------------- |
145e41f4b71Sopenharmony_ci| string | 返回设备MAC地址。 |
146e41f4b71Sopenharmony_ci
147e41f4b71Sopenharmony_ci**错误码**:
148e41f4b71Sopenharmony_ci
149e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
150e41f4b71Sopenharmony_ci
151e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
152e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
153e41f4b71Sopenharmony_ci| 9200001  | The application is not an administrator application of the device. |
154e41f4b71Sopenharmony_ci| 9200002  | The administrator application does not have permission to manage the device. |
155e41f4b71Sopenharmony_ci| 201      | Permission verification failed. The application does not have the permission required to call the API. |
156e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
157e41f4b71Sopenharmony_ci
158e41f4b71Sopenharmony_ci**示例:**
159e41f4b71Sopenharmony_ci
160e41f4b71Sopenharmony_ci```ts
161e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
162e41f4b71Sopenharmony_cilet wantTemp: Want = {
163e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
164e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
165e41f4b71Sopenharmony_ci};
166e41f4b71Sopenharmony_ci
167e41f4b71Sopenharmony_citry {
168e41f4b71Sopenharmony_ci  let result: string = networkManager.getMacSync(wantTemp, 'eth0');
169e41f4b71Sopenharmony_ci  console.info(`Succeeded in getting mac, result : ${result}`);
170e41f4b71Sopenharmony_ci} catch (err) {
171e41f4b71Sopenharmony_ci  console.error(`Failed to get mac. Code: ${err.code}, message: ${err.message}`);
172e41f4b71Sopenharmony_ci}
173e41f4b71Sopenharmony_ci```
174e41f4b71Sopenharmony_ci
175e41f4b71Sopenharmony_ci## networkManager.isNetworkInterfaceDisabledSync
176e41f4b71Sopenharmony_ci
177e41f4b71Sopenharmony_ciisNetworkInterfaceDisabledSync(admin: Want, networkInterface: string): boolean
178e41f4b71Sopenharmony_ci
179e41f4b71Sopenharmony_ci指定设备管理应用查询指定网络接口是否被禁用。
180e41f4b71Sopenharmony_ci
181e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK
182e41f4b71Sopenharmony_ci
183e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
184e41f4b71Sopenharmony_ci
185e41f4b71Sopenharmony_ci
186e41f4b71Sopenharmony_ci**参数:**
187e41f4b71Sopenharmony_ci
188e41f4b71Sopenharmony_ci| 参数名           | 类型                                                    | 必填 | 说明           |
189e41f4b71Sopenharmony_ci| ---------------- | ------------------------------------------------------- | ---- | -------------- |
190e41f4b71Sopenharmony_ci| admin            | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 设备管理应用。 |
191e41f4b71Sopenharmony_ci| networkInterface | string                                                  | 是   | 指定网络接口。 |
192e41f4b71Sopenharmony_ci
193e41f4b71Sopenharmony_ci**返回值:**
194e41f4b71Sopenharmony_ci
195e41f4b71Sopenharmony_ci| 类型    | 说明                                                         |
196e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
197e41f4b71Sopenharmony_ci| boolean | 返回指定网络接口是否被禁用,true表示该网络接口被禁用,false表示该网络接口未被禁用。 |
198e41f4b71Sopenharmony_ci
199e41f4b71Sopenharmony_ci**错误码**:
200e41f4b71Sopenharmony_ci
201e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
202e41f4b71Sopenharmony_ci
203e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
204e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
205e41f4b71Sopenharmony_ci| 9200001  | The application is not an administrator application of the device. |
206e41f4b71Sopenharmony_ci| 9200002  | The administrator application does not have permission to manage the device. |
207e41f4b71Sopenharmony_ci| 201      | Permission verification failed. The application does not have the permission required to call the API. |
208e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
209e41f4b71Sopenharmony_ci
210e41f4b71Sopenharmony_ci**示例:**
211e41f4b71Sopenharmony_ci
212e41f4b71Sopenharmony_ci```ts
213e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
214e41f4b71Sopenharmony_cilet wantTemp: Want = {
215e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
216e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
217e41f4b71Sopenharmony_ci};
218e41f4b71Sopenharmony_ci
219e41f4b71Sopenharmony_citry {
220e41f4b71Sopenharmony_ci  let result: boolean = networkManager.isNetworkInterfaceDisabledSync(wantTemp, 'eth0');
221e41f4b71Sopenharmony_ci  console.info(`Succeeded in querying network interface is disabled or not, result : ${result}`);
222e41f4b71Sopenharmony_ci} catch (err) {
223e41f4b71Sopenharmony_ci  console.error(`Failed to query network interface is disabled or not. Code: ${err.code}, message: ${err.message}`);
224e41f4b71Sopenharmony_ci}
225e41f4b71Sopenharmony_ci```
226e41f4b71Sopenharmony_ci
227e41f4b71Sopenharmony_ci## networkManager.setNetworkInterfaceDisabledSync
228e41f4b71Sopenharmony_ci
229e41f4b71Sopenharmony_cisetNetworkInterfaceDisabledSync(admin: Want, networkInterface: string, isDisabled: boolean): void
230e41f4b71Sopenharmony_ci
231e41f4b71Sopenharmony_ci指定设备管理应用禁止设备使用指定网络。
232e41f4b71Sopenharmony_ci
233e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK
234e41f4b71Sopenharmony_ci
235e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
236e41f4b71Sopenharmony_ci
237e41f4b71Sopenharmony_ci
238e41f4b71Sopenharmony_ci**参数:**
239e41f4b71Sopenharmony_ci
240e41f4b71Sopenharmony_ci| 参数名           | 类型                                                    | 必填 | 说明                                              |
241e41f4b71Sopenharmony_ci| ---------------- | ------------------------------------------------------- | ---- | ------------------------------------------------- |
242e41f4b71Sopenharmony_ci| admin            | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 设备管理应用。                                    |
243e41f4b71Sopenharmony_ci| networkInterface | string                                                  | 是   | 指定网络接口。                                    |
244e41f4b71Sopenharmony_ci| isDisabled       | boolean                                                 | 是   | true表示禁用该网络接口,false表示开启该网络接口。 |
245e41f4b71Sopenharmony_ci
246e41f4b71Sopenharmony_ci**错误码**:
247e41f4b71Sopenharmony_ci
248e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
249e41f4b71Sopenharmony_ci
250e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
251e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
252e41f4b71Sopenharmony_ci| 9200001  | The application is not an administrator application of the device. |
253e41f4b71Sopenharmony_ci| 9200002  | The administrator application does not have permission to manage the device. |
254e41f4b71Sopenharmony_ci| 201      | Permission verification failed. The application does not have the permission required to call the API. |
255e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
256e41f4b71Sopenharmony_ci
257e41f4b71Sopenharmony_ci**示例:**
258e41f4b71Sopenharmony_ci
259e41f4b71Sopenharmony_ci```ts
260e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
261e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
262e41f4b71Sopenharmony_cilet wantTemp: Want = {
263e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
264e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
265e41f4b71Sopenharmony_ci};
266e41f4b71Sopenharmony_ci
267e41f4b71Sopenharmony_citry {
268e41f4b71Sopenharmony_ci  networkManager.setNetworkInterfaceDisabledSync(wantTemp, 'eth0', true);
269e41f4b71Sopenharmony_ci  console.info(`Succeeded in setting network interface disabled`);
270e41f4b71Sopenharmony_ci} catch (err) {
271e41f4b71Sopenharmony_ci  console.error(`Failed to set network interface disabled. Code: ${err.code}, message: ${err.message}`);
272e41f4b71Sopenharmony_ci}
273e41f4b71Sopenharmony_ci```
274e41f4b71Sopenharmony_ci
275e41f4b71Sopenharmony_ci## networkManager.setGlobalProxySync
276e41f4b71Sopenharmony_ci
277e41f4b71Sopenharmony_cisetGlobalProxySync(admin: Want, httpProxy: connection.HttpProxy): void
278e41f4b71Sopenharmony_ci
279e41f4b71Sopenharmony_ci指定设备管理应用设置网络全局代理。
280e41f4b71Sopenharmony_ci
281e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK
282e41f4b71Sopenharmony_ci
283e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
284e41f4b71Sopenharmony_ci
285e41f4b71Sopenharmony_ci
286e41f4b71Sopenharmony_ci**参数:**
287e41f4b71Sopenharmony_ci
288e41f4b71Sopenharmony_ci| 参数名    | 类型                                                         | 必填 | 说明                       |
289e41f4b71Sopenharmony_ci| --------- | ------------------------------------------------------------ | ---- | -------------------------- |
290e41f4b71Sopenharmony_ci| admin     | [Want](../apis-ability-kit/js-apis-app-ability-want.md)      | 是   | 设备管理应用。             |
291e41f4b71Sopenharmony_ci| httpProxy | [connection.HttpProxy](../apis-network-kit/js-apis-net-connection.md#httpproxy10) | 是   | 网络全局Http代理配置信息。 |
292e41f4b71Sopenharmony_ci
293e41f4b71Sopenharmony_ci**错误码**:
294e41f4b71Sopenharmony_ci
295e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
296e41f4b71Sopenharmony_ci
297e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
298e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
299e41f4b71Sopenharmony_ci| 9200001  | The application is not an administrator application of the device. |
300e41f4b71Sopenharmony_ci| 9200002  | The administrator application does not have permission to manage the device. |
301e41f4b71Sopenharmony_ci| 201      | Permission verification failed. The application does not have the permission required to call the API. |
302e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
303e41f4b71Sopenharmony_ci
304e41f4b71Sopenharmony_ci**示例:**
305e41f4b71Sopenharmony_ci
306e41f4b71Sopenharmony_ci```ts
307e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
308e41f4b71Sopenharmony_ciimport { connection } from '@kit.NetworkKit';
309e41f4b71Sopenharmony_cilet wantTemp: Want = {
310e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
311e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
312e41f4b71Sopenharmony_ci};
313e41f4b71Sopenharmony_cilet exclusionStr: string = "192.168,baidu.com"
314e41f4b71Sopenharmony_cilet exclusionArray: Array<string> = exclusionStr.split(',');
315e41f4b71Sopenharmony_cilet httpProxy: connection.HttpProxy = {
316e41f4b71Sopenharmony_ci  host: "192.168.xx.xxx",
317e41f4b71Sopenharmony_ci  port: 8080,
318e41f4b71Sopenharmony_ci  exclusionList: exclusionArray
319e41f4b71Sopenharmony_ci};
320e41f4b71Sopenharmony_ci
321e41f4b71Sopenharmony_citry {
322e41f4b71Sopenharmony_ci  networkManager.setGlobalProxySync(wantTemp, httpProxy);
323e41f4b71Sopenharmony_ci  console.info(`Succeeded in setting network global proxy.`);
324e41f4b71Sopenharmony_ci} catch (err) {
325e41f4b71Sopenharmony_ci  console.error(`Failed to set network global proxy. Code: ${err.code}, message: ${err.message}`);
326e41f4b71Sopenharmony_ci}
327e41f4b71Sopenharmony_ci```
328e41f4b71Sopenharmony_ci
329e41f4b71Sopenharmony_ci## networkManager.getGlobalProxySync
330e41f4b71Sopenharmony_ci
331e41f4b71Sopenharmony_cigetGlobalProxySync(admin: Want): connection.HttpProxy
332e41f4b71Sopenharmony_ci
333e41f4b71Sopenharmony_ci指定设备管理应用获取网络全局代理。
334e41f4b71Sopenharmony_ci
335e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK
336e41f4b71Sopenharmony_ci
337e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
338e41f4b71Sopenharmony_ci
339e41f4b71Sopenharmony_ci
340e41f4b71Sopenharmony_ci**参数:**
341e41f4b71Sopenharmony_ci
342e41f4b71Sopenharmony_ci| 参数名 | 类型                                                    | 必填 | 说明           |
343e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------- | ---- | -------------- |
344e41f4b71Sopenharmony_ci| admin  | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 设备管理应用。 |
345e41f4b71Sopenharmony_ci
346e41f4b71Sopenharmony_ci**返回值:**
347e41f4b71Sopenharmony_ci
348e41f4b71Sopenharmony_ci| 类型                                                         | 说明                           |
349e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------------ |
350e41f4b71Sopenharmony_ci| [connection.HttpProxy](../apis-network-kit/js-apis-net-connection.md#httpproxy10) | 返回网络全局Http代理配置信息。 |
351e41f4b71Sopenharmony_ci
352e41f4b71Sopenharmony_ci**错误码**:
353e41f4b71Sopenharmony_ci
354e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
355e41f4b71Sopenharmony_ci
356e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
357e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
358e41f4b71Sopenharmony_ci| 9200001  | The application is not an administrator application of the device. |
359e41f4b71Sopenharmony_ci| 9200002  | The administrator application does not have permission to manage the device. |
360e41f4b71Sopenharmony_ci| 201      | Permission verification failed. The application does not have the permission required to call the API. |
361e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
362e41f4b71Sopenharmony_ci
363e41f4b71Sopenharmony_ci**示例:**
364e41f4b71Sopenharmony_ci
365e41f4b71Sopenharmony_ci```ts
366e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
367e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
368e41f4b71Sopenharmony_ciimport { connection } from '@kit.NetworkKit';
369e41f4b71Sopenharmony_cilet wantTemp: Want = {
370e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
371e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
372e41f4b71Sopenharmony_ci};
373e41f4b71Sopenharmony_ci
374e41f4b71Sopenharmony_citry {
375e41f4b71Sopenharmony_ci  let result: connection.HttpProxy = networkManager.getGlobalProxySync(wantTemp);
376e41f4b71Sopenharmony_ci  console.info(`Succeeded in getting network global proxy, result : ${JSON.stringify(result)}`);
377e41f4b71Sopenharmony_ci} catch (err) {
378e41f4b71Sopenharmony_ci  console.error(`Failed to get network global proxy. Code: ${err.code}, message: ${err.message}`);
379e41f4b71Sopenharmony_ci}
380e41f4b71Sopenharmony_ci```
381e41f4b71Sopenharmony_ci
382e41f4b71Sopenharmony_ci## networkManager.addFirewallRule
383e41f4b71Sopenharmony_ci
384e41f4b71Sopenharmony_ciaddFirewallRule(admin: Want, firewallRule: FirewallRule): void
385e41f4b71Sopenharmony_ci
386e41f4b71Sopenharmony_ci指定设备管理应用为设备添加防火墙过滤规则。<br/>
387e41f4b71Sopenharmony_ci添加了[Action](#action)为ALLOW规则后,将会默认添加DENY规则,不在ALLOW规则之内的网络数据包将会被丢弃或拦截。
388e41f4b71Sopenharmony_ci
389e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK
390e41f4b71Sopenharmony_ci
391e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
392e41f4b71Sopenharmony_ci
393e41f4b71Sopenharmony_ci
394e41f4b71Sopenharmony_ci**参数:**
395e41f4b71Sopenharmony_ci
396e41f4b71Sopenharmony_ci| 参数名       | 类型                                                    | 必填 | 说明                 |
397e41f4b71Sopenharmony_ci| ------------ | ------------------------------------------------------- | ---- | -------------------- |
398e41f4b71Sopenharmony_ci| admin        | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 设备管理应用。       |
399e41f4b71Sopenharmony_ci| firewallRule | [FirewallRule](#firewallrule)                           | 是   | 添加防火墙过滤规则。 |
400e41f4b71Sopenharmony_ci
401e41f4b71Sopenharmony_ci**错误码**:
402e41f4b71Sopenharmony_ci
403e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
404e41f4b71Sopenharmony_ci
405e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
406e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
407e41f4b71Sopenharmony_ci| 9200001  | The application is not an administrator application of the device. |
408e41f4b71Sopenharmony_ci| 9200002  | The administrator application does not have permission to manage the device. |
409e41f4b71Sopenharmony_ci| 201      | Permission verification failed. The application does not have the permission required to call the API. |
410e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
411e41f4b71Sopenharmony_ci
412e41f4b71Sopenharmony_ci**示例:**
413e41f4b71Sopenharmony_ci
414e41f4b71Sopenharmony_ci```ts
415e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
416e41f4b71Sopenharmony_ci
417e41f4b71Sopenharmony_cilet wantTemp: Want = {
418e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
419e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
420e41f4b71Sopenharmony_ci};
421e41f4b71Sopenharmony_cilet firewallRule: networkManager.FirewallRule = {
422e41f4b71Sopenharmony_ci  "srcAddr": "192.168.1.1-192.188.22.66",
423e41f4b71Sopenharmony_ci  "destAddr": "10.1.1.1",
424e41f4b71Sopenharmony_ci  "srcPort": "8080",
425e41f4b71Sopenharmony_ci  "destPort": "8080",
426e41f4b71Sopenharmony_ci  "appUid": "9696",
427e41f4b71Sopenharmony_ci  "direction": networkManager.Direction.OUTPUT,
428e41f4b71Sopenharmony_ci  "action": networkManager.Action.DENY,
429e41f4b71Sopenharmony_ci  "protocol": networkManager.Protocol.UDP,
430e41f4b71Sopenharmony_ci}
431e41f4b71Sopenharmony_ci
432e41f4b71Sopenharmony_cinetworkManager.addFirewallRule(wantTemp, firewallRule);
433e41f4b71Sopenharmony_ci```
434e41f4b71Sopenharmony_ci
435e41f4b71Sopenharmony_ci## networkManager.removeFirewallRule
436e41f4b71Sopenharmony_ci
437e41f4b71Sopenharmony_ciremoveFirewallRule(admin: Want, firewallRule?: FirewallRule): void
438e41f4b71Sopenharmony_ci
439e41f4b71Sopenharmony_ci指定设备管理应用移除设备防火墙过滤规则。<br/>
440e41f4b71Sopenharmony_ci移除规则后如果不存在[Action](#action)为ALLOW规则后,会将[addFirewallRule](#networkmanageraddfirewallrule)添加的默认DENY规则清空。
441e41f4b71Sopenharmony_ci
442e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK
443e41f4b71Sopenharmony_ci
444e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
445e41f4b71Sopenharmony_ci
446e41f4b71Sopenharmony_ci
447e41f4b71Sopenharmony_ci**参数:**
448e41f4b71Sopenharmony_ci
449e41f4b71Sopenharmony_ci| 参数名       | 类型                                                    | 必填 | 说明                                                 |
450e41f4b71Sopenharmony_ci| ------------ | ------------------------------------------------------- | ---- | ---------------------------------------------------- |
451e41f4b71Sopenharmony_ci| admin        | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 设备管理应用。                                       |
452e41f4b71Sopenharmony_ci| firewallRule | [FirewallRule](#firewallrule)                           | 否   | 移除防火墙过滤规则。值为空时,清空所有的防火墙规则。 |
453e41f4b71Sopenharmony_ci
454e41f4b71Sopenharmony_ci**错误码**:
455e41f4b71Sopenharmony_ci
456e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
457e41f4b71Sopenharmony_ci
458e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
459e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
460e41f4b71Sopenharmony_ci| 9200001  | The application is not an administrator application of the device. |
461e41f4b71Sopenharmony_ci| 9200002  | The administrator application does not have permission to manage the device. |
462e41f4b71Sopenharmony_ci| 201      | Permission verification failed. The application does not have the permission required to call the API. |
463e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
464e41f4b71Sopenharmony_ci
465e41f4b71Sopenharmony_ci**示例:**
466e41f4b71Sopenharmony_ci
467e41f4b71Sopenharmony_ci```ts
468e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
469e41f4b71Sopenharmony_ci
470e41f4b71Sopenharmony_cilet wantTemp: Want = {
471e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
472e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
473e41f4b71Sopenharmony_ci};
474e41f4b71Sopenharmony_ci// 移除指定的规则
475e41f4b71Sopenharmony_cilet firewallRule: networkManager.FirewallRule = {
476e41f4b71Sopenharmony_ci  "srcAddr": "192.168.1.1-192.188.22.66",
477e41f4b71Sopenharmony_ci  "destAddr": "10.1.1.1",
478e41f4b71Sopenharmony_ci  "srcPort": "8080",
479e41f4b71Sopenharmony_ci  "destPort": "8080",
480e41f4b71Sopenharmony_ci  "appUid": "9696",
481e41f4b71Sopenharmony_ci  "direction": networkManager.Direction.OUTPUT,
482e41f4b71Sopenharmony_ci  "action": networkManager.Action.DENY,
483e41f4b71Sopenharmony_ci  "protocol": networkManager.Protocol.UDP,
484e41f4b71Sopenharmony_ci}
485e41f4b71Sopenharmony_cinetworkManager.removeFirewallRule(wantTemp, firewallRule);
486e41f4b71Sopenharmony_ci
487e41f4b71Sopenharmony_ci// 清空所有规则
488e41f4b71Sopenharmony_cinetworkManager.removeFirewallRule(wantTemp);
489e41f4b71Sopenharmony_ci```
490e41f4b71Sopenharmony_ci
491e41f4b71Sopenharmony_ci## networkManager.getFirewallRules
492e41f4b71Sopenharmony_ci
493e41f4b71Sopenharmony_cigetFirewallRules(admin: Want): Array\<FirewallRule>
494e41f4b71Sopenharmony_ci
495e41f4b71Sopenharmony_ci指定设备管理应用查询防火墙过滤规则。
496e41f4b71Sopenharmony_ci
497e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK
498e41f4b71Sopenharmony_ci
499e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
500e41f4b71Sopenharmony_ci
501e41f4b71Sopenharmony_ci
502e41f4b71Sopenharmony_ci**参数:**
503e41f4b71Sopenharmony_ci
504e41f4b71Sopenharmony_ci| 参数名 | 类型                                                    | 必填 | 说明           |
505e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------- | ---- | -------------- |
506e41f4b71Sopenharmony_ci| admin  | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 设备管理应用。 |
507e41f4b71Sopenharmony_ci
508e41f4b71Sopenharmony_ci**返回值:**
509e41f4b71Sopenharmony_ci
510e41f4b71Sopenharmony_ci| 类型                                  | 说明                                                         |
511e41f4b71Sopenharmony_ci| ------------------------------------- | ------------------------------------------------------------ |
512e41f4b71Sopenharmony_ci| Array\<[FirewallRule](#firewallrule)> | 返回当前设备配置的防火墙过滤规则列表,当方法调用错误时会抛出异常。 |
513e41f4b71Sopenharmony_ci
514e41f4b71Sopenharmony_ci**错误码**:
515e41f4b71Sopenharmony_ci
516e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
517e41f4b71Sopenharmony_ci
518e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
519e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
520e41f4b71Sopenharmony_ci| 9200001  | The application is not an administrator application of the device. |
521e41f4b71Sopenharmony_ci| 9200002  | The administrator application does not have permission to manage the device. |
522e41f4b71Sopenharmony_ci| 201      | Permission verification failed. The application does not have the permission required to call the API. |
523e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
524e41f4b71Sopenharmony_ci
525e41f4b71Sopenharmony_ci**示例:**
526e41f4b71Sopenharmony_ci
527e41f4b71Sopenharmony_ci```ts
528e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
529e41f4b71Sopenharmony_ci
530e41f4b71Sopenharmony_cilet wantTemp: Want = {
531e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
532e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
533e41f4b71Sopenharmony_ci};
534e41f4b71Sopenharmony_cilet firewallRule: Array<networkManager.FirewallRule>;
535e41f4b71Sopenharmony_cifirewallRule = networkManager.getFirewallRules(wantTemp);
536e41f4b71Sopenharmony_ci```
537e41f4b71Sopenharmony_ci
538e41f4b71Sopenharmony_ci## networkManager.addDomainFilterRule
539e41f4b71Sopenharmony_ci
540e41f4b71Sopenharmony_ciaddDomainFilterRule(admin: Want, domainFilterRule: DomainFilterRule): void
541e41f4b71Sopenharmony_ci
542e41f4b71Sopenharmony_ci指定设备管理应用为设备添加域名过滤规则。<br/>
543e41f4b71Sopenharmony_ci添加了[Action](#action)为ALLOW规则后,将会默认添加DENY规则,不在ALLOW规则之内的域名解析数据包将会被丢弃或拦截。
544e41f4b71Sopenharmony_ci
545e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK
546e41f4b71Sopenharmony_ci
547e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
548e41f4b71Sopenharmony_ci
549e41f4b71Sopenharmony_ci
550e41f4b71Sopenharmony_ci**参数:**
551e41f4b71Sopenharmony_ci
552e41f4b71Sopenharmony_ci| 参数名           | 类型                                                    | 必填 | 说明               |
553e41f4b71Sopenharmony_ci| ---------------- | ------------------------------------------------------- | ---- | ------------------ |
554e41f4b71Sopenharmony_ci| admin            | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 设备管理应用。     |
555e41f4b71Sopenharmony_ci| domainFilterRule | [DomainFilterRule](#domainfilterrule)                   | 是   | 添加域名过滤规则。 |
556e41f4b71Sopenharmony_ci
557e41f4b71Sopenharmony_ci**错误码**:
558e41f4b71Sopenharmony_ci
559e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
560e41f4b71Sopenharmony_ci
561e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
562e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
563e41f4b71Sopenharmony_ci| 9200001  | The application is not an administrator application of the device. |
564e41f4b71Sopenharmony_ci| 9200002  | The administrator application does not have permission to manage the device. |
565e41f4b71Sopenharmony_ci| 201      | Permission verification failed. The application does not have the permission required to call the API. |
566e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
567e41f4b71Sopenharmony_ci
568e41f4b71Sopenharmony_ci**示例:**
569e41f4b71Sopenharmony_ci
570e41f4b71Sopenharmony_ci```ts
571e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
572e41f4b71Sopenharmony_ci
573e41f4b71Sopenharmony_cilet wantTemp: Want = {
574e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
575e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
576e41f4b71Sopenharmony_ci};
577e41f4b71Sopenharmony_cilet domainFilterRule: networkManager.DomainFilterRule = {
578e41f4b71Sopenharmony_ci  "domainName": "www.example.com",
579e41f4b71Sopenharmony_ci  "appUid": "9696",
580e41f4b71Sopenharmony_ci  "action": networkManager.Action.DENY,
581e41f4b71Sopenharmony_ci}
582e41f4b71Sopenharmony_ci
583e41f4b71Sopenharmony_cinetworkManager.addDomainFilterRule(wantTemp, domainFilterRule);
584e41f4b71Sopenharmony_ci```
585e41f4b71Sopenharmony_ci
586e41f4b71Sopenharmony_ci## networkManager.removeDomainFilterRule
587e41f4b71Sopenharmony_ci
588e41f4b71Sopenharmony_ciremoveDomainFilterRule(admin: Want, domainFilterRule?: DomainFilterRule): void
589e41f4b71Sopenharmony_ci
590e41f4b71Sopenharmony_ci指定设备管理应用移除设备域名过滤规则。<br/>
591e41f4b71Sopenharmony_ci移除规则后如果不存在[Action](#action)为ALLOW规则后,会将[addDomainFilterRule](#networkmanageradddomainfilterrule)添加的默认DENY规则清空。
592e41f4b71Sopenharmony_ci
593e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK
594e41f4b71Sopenharmony_ci
595e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
596e41f4b71Sopenharmony_ci
597e41f4b71Sopenharmony_ci
598e41f4b71Sopenharmony_ci**参数:**
599e41f4b71Sopenharmony_ci
600e41f4b71Sopenharmony_ci| 参数名           | 类型                                                    | 必填 | 说明                                             |
601e41f4b71Sopenharmony_ci| ---------------- | ------------------------------------------------------- | ---- | ------------------------------------------------ |
602e41f4b71Sopenharmony_ci| admin            | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 设备管理应用。                                   |
603e41f4b71Sopenharmony_ci| domainFilterRule | [DomainFilterRule](#domainfilterrule)                   | 否   | 移除域名过滤规则。值为空时,清空所有的域名规则。 |
604e41f4b71Sopenharmony_ci
605e41f4b71Sopenharmony_ci**错误码**:
606e41f4b71Sopenharmony_ci
607e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
608e41f4b71Sopenharmony_ci
609e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
610e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
611e41f4b71Sopenharmony_ci| 9200001  | The application is not an administrator application of the device. |
612e41f4b71Sopenharmony_ci| 9200002  | The administrator application does not have permission to manage the device. |
613e41f4b71Sopenharmony_ci| 201      | Permission verification failed. The application does not have the permission required to call the API. |
614e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
615e41f4b71Sopenharmony_ci
616e41f4b71Sopenharmony_ci**示例:**
617e41f4b71Sopenharmony_ci
618e41f4b71Sopenharmony_ci```ts
619e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
620e41f4b71Sopenharmony_ci
621e41f4b71Sopenharmony_cilet wantTemp: Want = {
622e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
623e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
624e41f4b71Sopenharmony_ci};
625e41f4b71Sopenharmony_ci// 移除指定的规则
626e41f4b71Sopenharmony_cilet domainFilterRule: networkManager.DomainFilterRule = {
627e41f4b71Sopenharmony_ci  "domainName": "www.example.com",
628e41f4b71Sopenharmony_ci  "appUid": "9696",
629e41f4b71Sopenharmony_ci  "action": networkManager.Action.DENY,
630e41f4b71Sopenharmony_ci}
631e41f4b71Sopenharmony_cinetworkManager.removeDomainFilterRule(wantTemp, domainFilterRule);
632e41f4b71Sopenharmony_ci
633e41f4b71Sopenharmony_ci// 清空所有规则
634e41f4b71Sopenharmony_cinetworkManager.removeDomainFilterRule(wantTemp);
635e41f4b71Sopenharmony_ci```
636e41f4b71Sopenharmony_ci
637e41f4b71Sopenharmony_ci## networkManager.getDomainFilterRules
638e41f4b71Sopenharmony_ci
639e41f4b71Sopenharmony_cigetDomainFilterRules(admin: Want): Array\<DomainFilterRule>
640e41f4b71Sopenharmony_ci
641e41f4b71Sopenharmony_ci指定设备管理应用查询域名过滤规则。
642e41f4b71Sopenharmony_ci
643e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK
644e41f4b71Sopenharmony_ci
645e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
646e41f4b71Sopenharmony_ci
647e41f4b71Sopenharmony_ci
648e41f4b71Sopenharmony_ci**参数:**
649e41f4b71Sopenharmony_ci
650e41f4b71Sopenharmony_ci| 参数名 | 类型                                                    | 必填 | 说明           |
651e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------- | ---- | -------------- |
652e41f4b71Sopenharmony_ci| admin  | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 设备管理应用。 |
653e41f4b71Sopenharmony_ci
654e41f4b71Sopenharmony_ci**返回值:**
655e41f4b71Sopenharmony_ci
656e41f4b71Sopenharmony_ci| 类型                                          | 说明                                                         |
657e41f4b71Sopenharmony_ci| --------------------------------------------- | ------------------------------------------------------------ |
658e41f4b71Sopenharmony_ci| Array\<[DomainFilterRule](#domainfilterrule)> | 返回当前设备配置的域名过滤规则列表,当方法调用错误时会抛出异常。 |
659e41f4b71Sopenharmony_ci
660e41f4b71Sopenharmony_ci**错误码**:
661e41f4b71Sopenharmony_ci
662e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
663e41f4b71Sopenharmony_ci
664e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
665e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
666e41f4b71Sopenharmony_ci| 9200001  | The application is not an administrator application of the device. |
667e41f4b71Sopenharmony_ci| 9200002  | The administrator application does not have permission to manage the device. |
668e41f4b71Sopenharmony_ci| 201      | Permission verification failed. The application does not have the permission required to call the API. |
669e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
670e41f4b71Sopenharmony_ci
671e41f4b71Sopenharmony_ci**示例:**
672e41f4b71Sopenharmony_ci
673e41f4b71Sopenharmony_ci```ts
674e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
675e41f4b71Sopenharmony_ci
676e41f4b71Sopenharmony_cilet wantTemp: Want = {
677e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
678e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
679e41f4b71Sopenharmony_ci};
680e41f4b71Sopenharmony_cilet domainFilterRule: Array<networkManager.DomainFilterRule>;
681e41f4b71Sopenharmony_cidomainFilterRule = networkManager.getDomainFilterRules(wantTemp);
682e41f4b71Sopenharmony_ci```
683e41f4b71Sopenharmony_ci
684e41f4b71Sopenharmony_ci## FirewallRule
685e41f4b71Sopenharmony_ci
686e41f4b71Sopenharmony_ci防火墙过滤规则。
687e41f4b71Sopenharmony_ci
688e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
689e41f4b71Sopenharmony_ci
690e41f4b71Sopenharmony_ci
691e41f4b71Sopenharmony_ci| 名称      | 类型                    | 必填 | 说明                                                         |
692e41f4b71Sopenharmony_ci| --------- | ----------------------- | ---- | ------------------------------------------------------------ |
693e41f4b71Sopenharmony_ci| srcAddr   | string                  | 否   | ip源地址。支持IP段,例如:192.168.0.0/22或者192.168.1.100-192.168.1.200 |
694e41f4b71Sopenharmony_ci| destAddr  | string                  | 否   | ip目标地址。支持IP段,例如:192.168.0.0/22或者192.168.1.100-192.168.1.200 |
695e41f4b71Sopenharmony_ci| srcPort   | string                  | 否   | 源端口。                                                     |
696e41f4b71Sopenharmony_ci| destPort  | string                  | 否   | 目标端口。                                                   |
697e41f4b71Sopenharmony_ci| appUid    | string                  | 否   | 应用uid。                                                    |
698e41f4b71Sopenharmony_ci| direction | [Direction](#direction) | 否   | 规则链。<br/>添加防护墙过滤规则时必填;移除防火墙时非必填,表示清空所有的[Direction](#direction)链。<br/>当值为空时srcAddr,destAddr,srcPort,destPort,appUid也必须传入空值。 |
699e41f4b71Sopenharmony_ci| action    | [Action](#action)       | 否   | 接收或者丢弃数据包。<br/>添加防护墙过滤规则时必填;移除防火墙时非必填,表示清空所有的匹配[Action](#action)规则的链。<br/>当值为空时srcAddr,destAddr,srcPort,destPort,appUid也必须传入空值。 |
700e41f4b71Sopenharmony_ci| protocol  | [Protocol](#protocol)   | 否   | 网络协议。当值为ALL或者ICMP时,不允许设置srcPort与destPort。 |
701e41f4b71Sopenharmony_ci
702e41f4b71Sopenharmony_ci## DomainFilterRule
703e41f4b71Sopenharmony_ci
704e41f4b71Sopenharmony_ci域名过滤规则。
705e41f4b71Sopenharmony_ci
706e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
707e41f4b71Sopenharmony_ci
708e41f4b71Sopenharmony_ci
709e41f4b71Sopenharmony_ci| 名称       | 类型              | 必填 | 说明                                                         |
710e41f4b71Sopenharmony_ci| ---------- | ----------------- | ---- | ------------------------------------------------------------ |
711e41f4b71Sopenharmony_ci| domainName | string            | 否   | 域名。添加域名过滤规则时必填。                               |
712e41f4b71Sopenharmony_ci| appUid     | string            | 否   | 应用uid。                                                    |
713e41f4b71Sopenharmony_ci| action     | [Action](#action) | 否   | 接收或者丢弃数据包。<br/>添加域名过滤规则时必填;移除域名过滤规则时非必填,表示清空所有的匹配[Action](#action)规则的链。<br/>当值为空时,domainName,appUid也必须传入空值。 |
714e41f4b71Sopenharmony_ci
715e41f4b71Sopenharmony_ci## Direction
716e41f4b71Sopenharmony_ci
717e41f4b71Sopenharmony_ci规则链。
718e41f4b71Sopenharmony_ci
719e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
720e41f4b71Sopenharmony_ci
721e41f4b71Sopenharmony_ci
722e41f4b71Sopenharmony_ci| 名称   | 值   | 说明     |
723e41f4b71Sopenharmony_ci| ------ | ---- | -------- |
724e41f4b71Sopenharmony_ci| INPUT  | 0    | 输入链。 |
725e41f4b71Sopenharmony_ci| OUTPUT | 1    | 输出链。 |
726e41f4b71Sopenharmony_ci
727e41f4b71Sopenharmony_ci## Action
728e41f4b71Sopenharmony_ci
729e41f4b71Sopenharmony_ci数据包的行为。
730e41f4b71Sopenharmony_ci
731e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
732e41f4b71Sopenharmony_ci
733e41f4b71Sopenharmony_ci
734e41f4b71Sopenharmony_ci| 名称  | 值   | 说明         |
735e41f4b71Sopenharmony_ci| ----- | ---- | ------------ |
736e41f4b71Sopenharmony_ci| ALLOW | 0    | 接收数据包。 |
737e41f4b71Sopenharmony_ci| DENY  | 1    | 丢弃数据包。 |
738e41f4b71Sopenharmony_ci
739e41f4b71Sopenharmony_ci## Protocol
740e41f4b71Sopenharmony_ci
741e41f4b71Sopenharmony_ci网络协议。
742e41f4b71Sopenharmony_ci
743e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
744e41f4b71Sopenharmony_ci
745e41f4b71Sopenharmony_ci
746e41f4b71Sopenharmony_ci| 名称 | 值   | 说明           |
747e41f4b71Sopenharmony_ci| ---- | ---- | -------------- |
748e41f4b71Sopenharmony_ci| ALL  | 0    | 全部网络协议。 |
749e41f4b71Sopenharmony_ci| TCP  | 1    | 网络协议TCP。  |
750e41f4b71Sopenharmony_ci| UDP  | 2    | 网络协议UDP。  |
751e41f4b71Sopenharmony_ci| ICMP | 3    | 网络协议ICMP。 |