openharmony 鸿蒙 js-apis-net-ethernet

2025-06-12 浏览 (1)

# @ohos.net.ethernet (Ethernet Connection Management)

The ethernet module provides Ethernet management functions such as obtaining the network IP address.

NOTE The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

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

HttpProxy

type HttpProxy = connection.HttpProxy;

Defines the network proxy configuration.

System capability: SystemCapability.Communication.NetManager.Ethernet

TypeDescription
connection.HttpProxyNetwork proxy configuration.

ethernet.getMacAddress14+

getMacAddress(): Promise<Array<MacAddressInfo>>

Obtains the names and MAC addresses of all Ethernet NICs. This API uses a promise to return the result.

Required permission: ohos.permission.GET_ETHERNET_LOCAL_MAC

System capability: SystemCapability.Communication.NetManager.Ethernet

Return value

TypeDescription
Promise<Array<MacAddressInfo>>Promise used to return the result.

Error codes

IDError Message
201Permission denied.
2200002Operation failed. Cannot connect to service.
2201005Device information does not exist.

Example

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+

Defines the name and MAC address of an Ethernet NIC.

System capability: SystemCapability.Communication.NetManager.Ethernet

NameTypeMandatoryDescription
ifacestringYesName of the Ethernet NIC.
macAddressstringYesMAC address of the Ethernet NIC.

你可能感兴趣的鸿蒙文章

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