• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.net.netFirewall (Network Firewall) (System API)
2
3The **netFirewall** module implements the firewall query functionality. It allows applications to query firewall interception records of the device.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 14. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8> The APIs provided by this module are system APIs.
9
10## Modules to Import
11
12```ts
13import netfirewall from '@ohos.net.netFirewall';
14```
15
16## netFirewall.getInterceptedRecords
17
18getInterceptedRecords(userId: number, requestParam: RequestParam): Promise<\InterceptedRecordPage>
19
20Obtains interception records based on the specified user ID. You need to specify the pagination query parameter when calling this API.
21
22**System API**: This is a system API.
23
24**Required permission**: ohos.permission.GET_NET_FIREWALL
25
26**System capability**: SystemCapability.Communication.NetManager.NetFirewall
27
28**Parameters**
29
30| Name      | Type                                                    | Mandatory| Description                                        |
31| ------------ | ------------------------------------------------------- | ---- | -------------------------------------------- |
32| userId       | number                                                  | Yes  | Existing user ID.|
33| requestParam | [RequestParam](js-apis-net-netfirewall.md#requestparam) | Yes  | Query parameter.                                  |
34
35**Return value**
36
37| Type                                                     | Description                           |
38| --------------------------------------------------------- | ------------------------------- |
39| Promise\<[InterceptedRecordPage](#interceptedrecordpage)> | Promise used to return the result, which is a list of interception records.|
40
41**Error codes**
42
43For details about the error codes, see [Network Connection Management Error Codes](errorcode-net-connection.md) and [Universal Error Codes](../errorcode-universal.md).
44| ID| Error Message                                                                       |
45| -------  | --------------------------------------------------------------------------------|
46| 201      | Permission denied.                                                              |
47| 202      | Non-system applications use system APIs.                                        |
48| 401      | Parameter error.                                                                |
49| 2100001  | Invalid parameter value.                                                        |
50| 2100002  | Operation failed. Cannot connect to service.                                    |
51| 2100003  | System internal error.                                                          |
52| 29400000 | The specified user does not exist.                                              |
53
54**Example**
55
56```ts
57import { netFirewall } '@kit.NetworkKit';
58import { BusinessError } from '@kit.BasicServicesKit';
59
60let interceptRecordParam: netFirewall.RequestParam = {
61  page: 1,
62  pageSize: 10,
63  orderField: netFirewall.NetFirewallOrderField.ORDER_BY_RECORD_TIME,
64  orderType: netFirewall.NetFirewallOrderType.ORDER_DESC
65};
66netFirewall.getInterceptedRecords(100, interceptRecordParam).then((result: netFirewall.InterceptedRecordPage) => {
67  console.info("result:", JSON.stringify(result));
68}, (error: BusinessError) => {
69  console.error("get intercept records failed: " + JSON.stringify(error));
70});
71```
72
73## InterceptedRecord
74
75Defines an interception record.
76
77**System API**: This is a system API.
78
79**System capability**: SystemCapability.Communication.NetManager.NetFirewall
80
81| Name      | Type  | Mandatory| Description               |
82|------------| -------|------|-------------------- |
83| time       | number | Yes  | Timestamp.           |
84| localIp    | string | No  | Local IP address.           |
85| remoteIp   | string | No  | Remote IP address.           |
86| localPort  | number | No  | Local port.         |
87| remotePort | number | No  | Remote port.         |
88| protocol   | number | No  | Transport layer protocol.       |
89| appUid     | number | No  | Application or service UID.|
90| domain     | string | No  | Domain name.             |
91
92## InterceptedRecordPage
93
94Defines the pagination structure for interception records.
95
96**System API**: This is a system API.
97
98**System capability**: SystemCapability.Communication.NetManager.NetFirewall
99
100| Name      | Type                                           | Mandatory| Description      |
101|------------| ----------------------------------------------- |------|----------  |
102| page       | number                                          | Yes  | Current page.|
103| pageSize   | number                                          | Yes  | Page size.|
104| totalPage  | number                                          | Yes  | Total number of pages.  |
105| data       | Array\<[InterceptedRecord](#interceptedrecord)> | Yes  | Page data.|
106