怎么样获取客户端MAC、IP地址、计算机名?
获取客户端MAC地址、IP地址、计算机名
<HTML><HEAD><TITLE>获取客户端MAC地址、IP地址、计算机名测试</TITLE>
<METAhttp-equiv=Content-Typecontent="text/html;charset=gb2312">
<SCRIPTlanguage=JScriptevent="OnCompleted(hResult,pErrorObject,pAsyncContext)"for=foo>
document.forms[0].txtMACAddr.value=unescape(MACAddr);
document.forms[0].txtIPAddr.value=unescape(IPAddr);
document.forms[0].txtDNSName.value=unescape(sDNSName);
//document.formbar.submit();
</SCRIPT>
<SCRIPTlanguage=JScriptevent=OnObjectReady(objObject,objAsyncContext)for=foo>
if(objObject.IPEnabled!=null&&objObject.IPEnabled!="undefined"&&objObject.IPEnabled==true)
{
if(objObject.MACAddress!=null&&objObject.MACAddress!="undefined")
MACAddr=objObject.MACAddress;
if(objObject.IPEnabled&&objObject.IPAddress(0)!=null&&objObject.IPAddress(0)!="undefined")
IPAddr=objObject.IPAddress(0);
if(objObject.DNSHostName!=null&&objObject.DNSHostName!="undefined")
sDNSName=objObject.DNSHostName;
}
</SCRIPT>
<METAcontent="MSHTML6.00.2800.1106"classid=CLSID:76A64158-CB41-11D1-8B02-00600806D9B6VIEWASTEXT></OBJECT>
<OBJECTclassid=CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223></OBJECT>
<SCRIPTlanguage=JScript>
varservice=locator.ConnectServer();
varMACAddr;
varIPAddr;
varDomainAddr;
varsDNSName;
service.Security_.ImpersonationLevel=3;
service.InstancesOfAsync(foo,'Win32_NetworkAdapterConfiguration');
</SCRIPT>
<FORMaction=NICPost.aspmethod=post><INPUTvalue=00:05:5D:0E:C7:FA<INPUTvalue=192.168.0.2<INPUTvalue=typ</FORM></BODY></HTML>
<METAhttp-equiv=Content-Typecontent="text/html;charset=gb2312">
<SCRIPTlanguage=JScriptevent="OnCompleted(hResult,pErrorObject,pAsyncContext)"for=foo>
document.forms[0].txtMACAddr.value=unescape(MACAddr);
document.forms[0].txtIPAddr.value=unescape(IPAddr);
document.forms[0].txtDNSName.value=unescape(sDNSName);
//document.formbar.submit();
</SCRIPT>
<SCRIPTlanguage=JScriptevent=OnObjectReady(objObject,objAsyncContext)for=foo>
if(objObject.IPEnabled!=null&&objObject.IPEnabled!="undefined"&&objObject.IPEnabled==true)
{
if(objObject.MACAddress!=null&&objObject.MACAddress!="undefined")
MACAddr=objObject.MACAddress;
if(objObject.IPEnabled&&objObject.IPAddress(0)!=null&&objObject.IPAddress(0)!="undefined")
IPAddr=objObject.IPAddress(0);
if(objObject.DNSHostName!=null&&objObject.DNSHostName!="undefined")
sDNSName=objObject.DNSHostName;
}
</SCRIPT>
<METAcontent="MSHTML6.00.2800.1106"classid=CLSID:76A64158-CB41-11D1-8B02-00600806D9B6VIEWASTEXT></OBJECT>
<OBJECTclassid=CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223></OBJECT>
<SCRIPTlanguage=JScript>
varservice=locator.ConnectServer();
varMACAddr;
varIPAddr;
varDomainAddr;
varsDNSName;
service.Security_.ImpersonationLevel=3;
service.InstancesOfAsync(foo,'Win32_NetworkAdapterConfiguration');
</SCRIPT>
<FORMaction=NICPost.aspmethod=post><INPUTvalue=00:05:5D:0E:C7:FA<INPUTvalue=192.168.0.2<INPUTvalue=typ</FORM></BODY></HTML>
获取本级MAC地址、IP地址、计算机名
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
usingSystem.Management;
usingSystem.Net;
privatevoidForm1_Shown(objectsender,EventArgse)
{
stringname=string.Empty,mac=string.Empty;
name=Dns.GetHostName();//本机名
textBoxName.Text=name;
StringBuilderip=newStringBuilder();
IPAddress[]addressList=Dns.GetHostAddresses(Dns.GetHostName());//framework2.0
foreach(IPAddressiinaddressList)
{
ip.Append(i);
}
textBoxIP.Text=ip.ToString();//ip
//IPAddress[]addressList=Dns.GetHostEntry(Dns.GetHostName()).AddressList;
//for(inti=0;i<addressList.Length;i++)
//{
//ip.Append(addressList[i]);
//}
//textBoxIP.Text=ip.ToString();
ManagementClassmc=newManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollectionmoc=mc.GetInstances();
foreach(ManagementObjectmoinmoc)
{
if(mo["IPEnabled"].ToString()=="True")
mac=mo["MacAddress"].ToString();
}
textBoxMAC.Text=mac;//mac
}
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
usingSystem.Management;
usingSystem.Net;
privatevoidForm1_Shown(objectsender,EventArgse)
{
stringname=string.Empty,mac=string.Empty;
name=Dns.GetHostName();//本机名
textBoxName.Text=name;
StringBuilderip=newStringBuilder();
IPAddress[]addressList=Dns.GetHostAddresses(Dns.GetHostName());//framework2.0
foreach(IPAddressiinaddressList)
{
ip.Append(i);
}
textBoxIP.Text=ip.ToString();//ip
//IPAddress[]addressList=Dns.GetHostEntry(Dns.GetHostName()).AddressList;
//for(inti=0;i<addressList.Length;i++)
//{
//ip.Append(addressList[i]);
//}
//textBoxIP.Text=ip.ToString();
ManagementClassmc=newManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollectionmoc=mc.GetInstances();
foreach(ManagementObjectmoinmoc)
{
if(mo["IPEnabled"].ToString()=="True")
mac=mo["MacAddress"].ToString();
}
textBoxMAC.Text=mac;//mac
}
本文地址:http://www.45fan.com/a/question/73950.html