获取mac 地址
This commit is contained in:
parent
147631122b
commit
5d8bad21de
@ -5,6 +5,7 @@ using System.IO;
|
|||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using Wpf_AiSportsMicrospace.Common;
|
||||||
|
|
||||||
namespace Common
|
namespace Common
|
||||||
{
|
{
|
||||||
@ -18,7 +19,7 @@ namespace Common
|
|||||||
|
|
||||||
public static void Init(IConfiguration configuration)
|
public static void Init(IConfiguration configuration)
|
||||||
{
|
{
|
||||||
Code = configuration["Code"] ?? "";
|
Code = Utils.GetMacAddress() ?? configuration["SchoolCode"] ?? "";
|
||||||
SchoolCode = configuration["SchoolCode"] ?? "";
|
SchoolCode = configuration["SchoolCode"] ?? "";
|
||||||
BackendUrl = configuration["BackendUrl"] ?? "";
|
BackendUrl = configuration["BackendUrl"] ?? "";
|
||||||
Version = configuration["Version"] ?? "";
|
Version = configuration["Version"] ?? "";
|
||||||
|
|||||||
@ -7,6 +7,7 @@ using SixLabors.ImageSharp.Processing;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net.NetworkInformation;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -321,5 +322,31 @@ namespace Wpf_AiSportsMicrospace.Common
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取本机Mac地址
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string GetMacAddress()
|
||||||
|
{
|
||||||
|
// 获取所有网络接口
|
||||||
|
var nics = NetworkInterface.GetAllNetworkInterfaces();
|
||||||
|
|
||||||
|
// 过滤掉不活动的和虚拟网卡
|
||||||
|
var activeNics = nics
|
||||||
|
.Where(n => n.OperationalStatus == OperationalStatus.Up &&
|
||||||
|
n.NetworkInterfaceType != NetworkInterfaceType.Loopback &&
|
||||||
|
n.NetworkInterfaceType != NetworkInterfaceType.Tunnel)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
if (activeNics.Count == 0)
|
||||||
|
return string.Empty;
|
||||||
|
|
||||||
|
// 获取第一个活跃网卡的 MAC 地址
|
||||||
|
var macBytes = activeNics[0].GetPhysicalAddress().GetAddressBytes();
|
||||||
|
|
||||||
|
// 转成常用的 XX-XX-XX-XX-XX-XX 格式
|
||||||
|
return string.Join("-", macBytes.Select(b => b.ToString("X2")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"DefaultConnection": "Data Source=rm-uf64b8oxdt19pfyxfao.sqlserver.rds.aliyuncs.com;Database=AiSportsMicrospaceDB_QA;User ID=qa;Password=Admin@123;Connect Timeout=500;TrustServerCertificate=True;"
|
"DefaultConnection": "Data Source=rm-uf64b8oxdt19pfyxfao.sqlserver.rds.aliyuncs.com;Database=AiSportsMicrospaceDB_QA;User ID=qa;Password=Admin@123;Connect Timeout=500;TrustServerCertificate=True;"
|
||||||
},
|
},
|
||||||
"Code": "04-68-74-3F-87-72",
|
"Code": "C0-E3-50-3E-45-68",
|
||||||
"SchoolCode": "202501060001",
|
"SchoolCode": "202501060001",
|
||||||
"Version": "1.0.0",
|
"Version": "1.0.0",
|
||||||
"BackendUrl": "http://localhost:9991/api/StudentFace"
|
"BackendUrl": "http://localhost:9991/api/StudentFace"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user