1# @ohos.net.ethernet (以太网连接管理)
2
3以太网连接管理主要提供有线网络能力,提供获取有线网络的IP地址等信息。
4
5> **说明:**
6> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
7
8## 导入模块
9
10```ts
11import { ethernet } from '@kit.NetworkKit';
12```
13
14## HttpProxy
15
16type HttpProxy = connection.HttpProxy;
17
18网络代理配置信息。
19
20**系统能力**:SystemCapability.Communication.NetManager.Ethernet
21
22| 类型 | 说明                                       |
23| ------- | ----------------------------------------|
24| connection.HttpProxy     | 网络代理配置信息。      |
25
26
27## ethernet.getMacAddress<sup>14+</sup>
28
29getMacAddress(): Promise\<Array\<MacAddressInfo>>
30
31获取所有以太网网卡名称及MAC地址信息,使用Promise方式作为异步方法。
32
33**需要权限**:ohos.permission.GET_ETHERNET_LOCAL_MAC
34
35**系统能力**:SystemCapability.Communication.NetManager.Ethernet
36
37**返回值:**
38
39| 类型                                                    | 说明                               |
40|-------------------------------------------------------| ---------------------------------- |
41| Promise\<Array[\<MacAddressInfo>](#macaddressinfo14)> | 以Promise形式返回接口信息。        |
42
43**错误码:**
44
45| 错误码ID | 错误信息                                 |
46| ------- | ----------------------------------------|
47| 201     | Permission denied.                      |
48| 2200002 | Failed to connect to the service.       |
49| 2201005 | Device information does not exist.  |
50
51**示例:**
52
53```ts
54import { ethernet } from '@kit.NetworkKit';
55import { BusinessError } from '@kit.BasicServicesKit';
56
57ethernet.getMacAddress().then((data: Array<ethernet.MacAddressInfo>) => {
58  console.info("getMacAddress promise data = " + JSON.stringify(data));
59}).catch((error: BusinessError) => {
60  console.error("getMacAddress promise error = " + JSON.stringify(error));
61});
62```
63
64## MacAddressInfo<sup>14+</sup>
65以太网网卡名称及MAC地址信息。
66
67**系统能力**:SystemCapability.Communication.NetManager.Ethernet
68
69| 名称         | 类型                    | 必填 | 说明                                                 |
70| ------------ | ----------------------- | --- | ---------------------------------------------------- |
71| iface        | string                  |  是 | 以太网卡名称。                                        |
72| macAddress       | string                |  是 | 以太网卡MAC地址信息。 |
73