openharmony 鸿蒙 js-apis-net-netfirewall-sys

2025-06-12 浏览 (1)

@ohos.net.netFirewall (Network Firewall) (System API)

The netFirewall module implements the firewall query functionality. It allows applications to query firewall interception records of the device.

NOTE

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. The APIs provided by this module are system APIs.

Modules to Import

import netfirewall from '@ohos.net.netFirewall';

netFirewall.getInterceptedRecords

getInterceptedRecords(userId: number, requestParam: RequestParam): Promise<\InterceptedRecordPage>

Obtains interception records based on the specified user ID. You need to specify the pagination query parameter when calling this API.

System API: This is a system API.

Required permission: ohos.permission.GET_NET_FIREWALL

System capability: SystemCapability.Communication.NetManager.NetFirewall

Parameters

NameTypeMandatoryDescription
userIdnumberYesExisting user ID.
requestParamRequestParamYesQuery parameter.

Return value

TypeDescription
Promise<InterceptedRecordPage>Promise used to return the result, which is a list of interception records.

Error codes

For details about the error codes, see Network Connection Management Error Codes and Universal Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
2100001Invalid parameter value.
2100002Operation failed. Cannot connect to service.
2100003System internal error.
29400000The specified user does not exist.

Example

import { netFirewall } '@kit.NetworkKit';
import { BusinessError } from '@kit.BasicServicesKit';

let interceptRecordParam: netFirewall.RequestParam = {
  page: 1,
  pageSize: 10,
  orderField: netFirewall.NetFirewallOrderField.ORDER_BY_RECORD_TIME,
  orderType: netFirewall.NetFirewallOrderType.ORDER_DESC
};
netFirewall.getInterceptedRecords(100, interceptRecordParam).then((result: netFirewall.InterceptedRecordPage) => {
  console.info("result:", JSON.stringify(result));
}, (error: BusinessError) => {
  console.error("get intercept records failed: " + JSON.stringify(error));
});

InterceptedRecord

Defines an interception record.

System API: This is a system API.

System capability: SystemCapability.Communication.NetManager.NetFirewall

NameTypeMandatoryDescription
timenumberYesTimestamp.
localIpstringNoLocal IP address.
remoteIpstringNoRemote IP address.
localPortnumberNoLocal port.
remotePortnumberNoRemote port.
protocolnumberNoTransport layer protocol.
appUidnumberNoApplication or service UID.
domainstringNoDomain name.

InterceptedRecordPage

Defines the pagination structure for interception records.

System API: This is a system API.

System capability: SystemCapability.Communication.NetManager.NetFirewall

NameTypeMandatoryDescription
pagenumberYesCurrent page.
pageSizenumberYesPage size.
totalPagenumberYesTotal number of pages.
dataArray<InterceptedRecord>YesPage data.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Network Kit

harmony 鸿蒙NetConn_ConnectionProperties

harmony 鸿蒙NetConn_HttpProxy

harmony 鸿蒙NetConn_NetAddr

harmony 鸿蒙NetConn_NetCapabilities

harmony 鸿蒙NetConn_NetConnCallback

harmony 鸿蒙NetConn_NetHandle

harmony 鸿蒙NetConn_NetHandleList

harmony 鸿蒙NetConn_NetSpecifier

harmony 鸿蒙NetConn_Route

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/6iGDBU