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