本文介绍了需要找出用户MAC地址和IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
In my project, we need to find out User MAC Address and IP Address kindly Provide the sample code (using C# Code behind or JavaScript or ActiveX controls). Thanks in Advance
推荐答案
var macAddress = "";
var ipAddress = "";
var computerName = "";
var wmi = GetObject("winmgmts:{impersonationLevel=impersonate}");
e = new Enumerator(wmi.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True"));
for(; !e.atEnd(); e.moveNext()) {
var s = e.item();
macAddress = s.MACAddress;
ipAddress = s.IPAddress(0);
computerName = s.DNSHostName;
}
C#
使用system.net
使用System.Net.NetworkInformation
IPAddressInformation类(System.Net.NetworkInformation) [ ^ ]
PhysicalAddress类(System.Net.NetworkInformation) [ ^ ]用于mac地址
C#
using system.net
using System.Net.NetworkInformation
IPAddressInformation Class (System.Net.NetworkInformation)[^]
PhysicalAddress Class (System.Net.NetworkInformation)[^] is for mac address
这篇关于需要找出用户MAC地址和IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!