openharmony 鸿蒙 js-apis-net-ethernet

2025-06-16 浏览 (1)

@ohos.net.ethernet (以太网连接管理)

本模块提供以太网连接管理能力,包括有线网络能力、获取有线网络的IP地址等信息。

说明: 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

导入模块

import { ethernet } from '@kit.NetworkKit';

HttpProxy

type HttpProxy = connection.HttpProxy

网络代理配置信息。

系统能力:SystemCapability.Communication.NetManager.Ethernet

类型说明
connection.HttpProxy网络代理配置信息。

ethernet.getMacAddress14+

getMacAddress(): Promise<Array<MacAddressInfo>>

获取所有以太网网卡名称及对应网卡的MAC地址信息,使用Promise方式作为异步方法。

需要权限:ohos.permission.GET_ETHERNET_LOCAL_MAC

系统能力:SystemCapability.Communication.NetManager.Ethernet

返回值:

类型说明
Promise<Array<MacAddressInfo>>以Promise形式返回接口信息。

错误码:

错误码ID错误信息
201Permission denied.
2200002Operation failed. Cannot connect to service.
2201005Device information does not exist.

示例:

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

ethernet.getMacAddress().then((data: Array<ethernet.MacAddressInfo>) => {
  console.info("getMacAddress promise data = " + JSON.stringify(data));
}).catch((error: BusinessError) => {
  console.error("getMacAddress promise error = " + JSON.stringify(error));
});

MacAddressInfo14+

以太网网卡名称及MAC地址信息。

系统能力:SystemCapability.Communication.NetManager.Ethernet

名称类型必填说明
ifacestring以太网网卡名称。
macAddressstring以太网网卡MAC地址信息。

你可能感兴趣的鸿蒙文章

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/XD1mGx