|
发表于 2025-5-28 18:45:56
|
显示全部楼层
翻译了一下
using System;
using System.Net;
using System.Net.NetworkInformation;
class EthernetAddressHost
{
static void Main(string[] args)
{
try {
// 获取第一个活跃的以太网适配器MAC地址
string macAddress = GetActiveEthernetMAC();
Console.WriteLine($"Ethernet MAC: {macAddress}");
// 模拟传递给后处理器的逻辑
PostProcessor.SendToProcessor(macAddress);
Console.WriteLine("Address transferred to post processor successfully");
}
catch (Exception ex) {
Console.WriteLine($"Error: {ex.Message}");
}
}
static string GetActiveEthernetMAC()
{
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
if (nic.NetworkInterfaceType == NetworkInterfaceType.Ethernet &&
nic.OperationalStatus == OperationalStatus.Up)
{
return nic.GetPhysicalAddress().ToString();
}
}
throw new Exception("No active Ethernet adapter found");
}
}
// 后处理器模拟接口
class PostProcessor
{
public static void SendToProcessor(string macAddress)
{
// 实际实现需根据后处理器API调整
File.WriteAllText("mac_address.txt", macAddress);
}
}
|
|