5 个解决方案
#1
沙发
#2
<html>
<head>
<title>WMI Scripting HTML</title>
<script FOR="foo" EVENT="OnCompleted(hResult,pErrorObject, pAsyncContext)" LANGUAGE="JScript">
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>
<script FOR="foo" EVENT="OnObjectReady(objObject,objAsyncContext)" LANGUAGE="JScript">
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>
</head>
<body>
<object classid="CLSID:76A64158-CB41-11D1-8B02-00600806D9B6" id="locator" VIEWASTEXT>
</object>
<object classid="CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223" id="foo">
</object>
<script LANGUAGE="JScript">
var service = locator.ConnectServer();
var MACAddr ;
var IPAddr ;
var DomainAddr;
var sDNSName;
service.Security_.ImpersonationLevel=3;
service.InstancesOfAsync(foo, 'Win32_NetworkAdapterConfiguration');
</script>
<form method="POST" action="NICPost.asp" id="formfoo" name="formbar">
<input type=text name="txtMACAddr">
<input type=text name="txtIPAddr">
<input type=text name="txtDNSName">
</form>
</body>
</html>
<head>
<title>WMI Scripting HTML</title>
<script FOR="foo" EVENT="OnCompleted(hResult,pErrorObject, pAsyncContext)" LANGUAGE="JScript">
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>
<script FOR="foo" EVENT="OnObjectReady(objObject,objAsyncContext)" LANGUAGE="JScript">
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>
</head>
<body>
<object classid="CLSID:76A64158-CB41-11D1-8B02-00600806D9B6" id="locator" VIEWASTEXT>
</object>
<object classid="CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223" id="foo">
</object>
<script LANGUAGE="JScript">
var service = locator.ConnectServer();
var MACAddr ;
var IPAddr ;
var DomainAddr;
var sDNSName;
service.Security_.ImpersonationLevel=3;
service.InstancesOfAsync(foo, 'Win32_NetworkAdapterConfiguration');
</script>
<form method="POST" action="NICPost.asp" id="formfoo" name="formbar">
<input type=text name="txtMACAddr">
<input type=text name="txtIPAddr">
<input type=text name="txtDNSName">
</form>
</body>
</html>
#3
获取服务器的IP地址方法以DNS法较为简单实用,如下:
private void ButtonIP_Click(object sender, System.EventArgs e)
{ System.Net.IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList;
if ( addressList.Length>1)
{ TextLIP.Text = addressList[0].ToString();
TextSIP.Text = addressList[1].ToString();
}
else
{
TextLIP.Text = addressList[0].ToString();
TextSIP.Text = "没有可用的连接";
}
}
获取服务器的IP地址与MAC地址另一方法如下:
using System.Management;
string stringMAC = "";
string stringIP = "";
ManagementClass MC = new ManagementClass "Win32_NetworkAdapterConfiguration");
ManagementObjectCollection MOC= MC.GetInstances();
foreach(ManagementObject MO in MOC)
{
if ((bool)MO["IPEnabled"] == true)
{
stringMAC += MO["MACAddress"].ToString();
TextMAC.Text = stringMAC.ToString();
string[] IPAddresses = (string[]) MO["IPAddress"];
if(IPAddresses.Length > 0)
stringIP = IPAddresses[0];
TextIP.Text = stringIP.ToString();
}
}
获取客户端本机的IP地址相当简易,方法如下:
using System.Net;
TextIP.Text=Page.Request.UserHostAddress;
如要获取客户端本机的MAC地址就相对复杂些,得导入调用两个API,用ARP协议获取,但这样只能获取到同网段机器的MAC,对于跨网段的得利用IP扫描或cmd中nbtstat命令获取MAC地址。也可通过读取系统注册表值或WMI的数据库来获取。
private void ButtonIP_Click(object sender, System.EventArgs e)
{ System.Net.IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList;
if ( addressList.Length>1)
{ TextLIP.Text = addressList[0].ToString();
TextSIP.Text = addressList[1].ToString();
}
else
{
TextLIP.Text = addressList[0].ToString();
TextSIP.Text = "没有可用的连接";
}
}
获取服务器的IP地址与MAC地址另一方法如下:
using System.Management;
string stringMAC = "";
string stringIP = "";
ManagementClass MC = new ManagementClass "Win32_NetworkAdapterConfiguration");
ManagementObjectCollection MOC= MC.GetInstances();
foreach(ManagementObject MO in MOC)
{
if ((bool)MO["IPEnabled"] == true)
{
stringMAC += MO["MACAddress"].ToString();
TextMAC.Text = stringMAC.ToString();
string[] IPAddresses = (string[]) MO["IPAddress"];
if(IPAddresses.Length > 0)
stringIP = IPAddresses[0];
TextIP.Text = stringIP.ToString();
}
}
获取客户端本机的IP地址相当简易,方法如下:
using System.Net;
TextIP.Text=Page.Request.UserHostAddress;
如要获取客户端本机的MAC地址就相对复杂些,得导入调用两个API,用ARP协议获取,但这样只能获取到同网段机器的MAC,对于跨网段的得利用IP扫描或cmd中nbtstat命令获取MAC地址。也可通过读取系统注册表值或WMI的数据库来获取。
#4
问题已经解决,虽不是大家所说明的那些情况,但还是要感谢各位,为共同学习,现在把问题的原因写出来,与大家共享,也许以后有人会需要:
假设我的机器MAC是00-15-58-EE-A8-D0,那么由SendARP获取的MAC地址是Int64的数值,转换为字符串后应该是0DA8EE585100,但作为数值转换为字符串后,其前边的0被舍去了,所以就不是12位的字符串,而变成了11位,所以再转换为00-15-58-EE-A8-D0的形式时就会出错。
假设我的机器MAC是00-15-58-EE-A8-D0,那么由SendARP获取的MAC地址是Int64的数值,转换为字符串后应该是0DA8EE585100,但作为数值转换为字符串后,其前边的0被舍去了,所以就不是12位的字符串,而变成了11位,所以再转换为00-15-58-EE-A8-D0的形式时就会出错。
#5
mark
#1
沙发
#2
<html>
<head>
<title>WMI Scripting HTML</title>
<script FOR="foo" EVENT="OnCompleted(hResult,pErrorObject, pAsyncContext)" LANGUAGE="JScript">
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>
<script FOR="foo" EVENT="OnObjectReady(objObject,objAsyncContext)" LANGUAGE="JScript">
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>
</head>
<body>
<object classid="CLSID:76A64158-CB41-11D1-8B02-00600806D9B6" id="locator" VIEWASTEXT>
</object>
<object classid="CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223" id="foo">
</object>
<script LANGUAGE="JScript">
var service = locator.ConnectServer();
var MACAddr ;
var IPAddr ;
var DomainAddr;
var sDNSName;
service.Security_.ImpersonationLevel=3;
service.InstancesOfAsync(foo, 'Win32_NetworkAdapterConfiguration');
</script>
<form method="POST" action="NICPost.asp" id="formfoo" name="formbar">
<input type=text name="txtMACAddr">
<input type=text name="txtIPAddr">
<input type=text name="txtDNSName">
</form>
</body>
</html>
<head>
<title>WMI Scripting HTML</title>
<script FOR="foo" EVENT="OnCompleted(hResult,pErrorObject, pAsyncContext)" LANGUAGE="JScript">
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>
<script FOR="foo" EVENT="OnObjectReady(objObject,objAsyncContext)" LANGUAGE="JScript">
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>
</head>
<body>
<object classid="CLSID:76A64158-CB41-11D1-8B02-00600806D9B6" id="locator" VIEWASTEXT>
</object>
<object classid="CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223" id="foo">
</object>
<script LANGUAGE="JScript">
var service = locator.ConnectServer();
var MACAddr ;
var IPAddr ;
var DomainAddr;
var sDNSName;
service.Security_.ImpersonationLevel=3;
service.InstancesOfAsync(foo, 'Win32_NetworkAdapterConfiguration');
</script>
<form method="POST" action="NICPost.asp" id="formfoo" name="formbar">
<input type=text name="txtMACAddr">
<input type=text name="txtIPAddr">
<input type=text name="txtDNSName">
</form>
</body>
</html>
#3
获取服务器的IP地址方法以DNS法较为简单实用,如下:
private void ButtonIP_Click(object sender, System.EventArgs e)
{ System.Net.IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList;
if ( addressList.Length>1)
{ TextLIP.Text = addressList[0].ToString();
TextSIP.Text = addressList[1].ToString();
}
else
{
TextLIP.Text = addressList[0].ToString();
TextSIP.Text = "没有可用的连接";
}
}
获取服务器的IP地址与MAC地址另一方法如下:
using System.Management;
string stringMAC = "";
string stringIP = "";
ManagementClass MC = new ManagementClass "Win32_NetworkAdapterConfiguration");
ManagementObjectCollection MOC= MC.GetInstances();
foreach(ManagementObject MO in MOC)
{
if ((bool)MO["IPEnabled"] == true)
{
stringMAC += MO["MACAddress"].ToString();
TextMAC.Text = stringMAC.ToString();
string[] IPAddresses = (string[]) MO["IPAddress"];
if(IPAddresses.Length > 0)
stringIP = IPAddresses[0];
TextIP.Text = stringIP.ToString();
}
}
获取客户端本机的IP地址相当简易,方法如下:
using System.Net;
TextIP.Text=Page.Request.UserHostAddress;
如要获取客户端本机的MAC地址就相对复杂些,得导入调用两个API,用ARP协议获取,但这样只能获取到同网段机器的MAC,对于跨网段的得利用IP扫描或cmd中nbtstat命令获取MAC地址。也可通过读取系统注册表值或WMI的数据库来获取。
private void ButtonIP_Click(object sender, System.EventArgs e)
{ System.Net.IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList;
if ( addressList.Length>1)
{ TextLIP.Text = addressList[0].ToString();
TextSIP.Text = addressList[1].ToString();
}
else
{
TextLIP.Text = addressList[0].ToString();
TextSIP.Text = "没有可用的连接";
}
}
获取服务器的IP地址与MAC地址另一方法如下:
using System.Management;
string stringMAC = "";
string stringIP = "";
ManagementClass MC = new ManagementClass "Win32_NetworkAdapterConfiguration");
ManagementObjectCollection MOC= MC.GetInstances();
foreach(ManagementObject MO in MOC)
{
if ((bool)MO["IPEnabled"] == true)
{
stringMAC += MO["MACAddress"].ToString();
TextMAC.Text = stringMAC.ToString();
string[] IPAddresses = (string[]) MO["IPAddress"];
if(IPAddresses.Length > 0)
stringIP = IPAddresses[0];
TextIP.Text = stringIP.ToString();
}
}
获取客户端本机的IP地址相当简易,方法如下:
using System.Net;
TextIP.Text=Page.Request.UserHostAddress;
如要获取客户端本机的MAC地址就相对复杂些,得导入调用两个API,用ARP协议获取,但这样只能获取到同网段机器的MAC,对于跨网段的得利用IP扫描或cmd中nbtstat命令获取MAC地址。也可通过读取系统注册表值或WMI的数据库来获取。
#4
问题已经解决,虽不是大家所说明的那些情况,但还是要感谢各位,为共同学习,现在把问题的原因写出来,与大家共享,也许以后有人会需要:
假设我的机器MAC是00-15-58-EE-A8-D0,那么由SendARP获取的MAC地址是Int64的数值,转换为字符串后应该是0DA8EE585100,但作为数值转换为字符串后,其前边的0被舍去了,所以就不是12位的字符串,而变成了11位,所以再转换为00-15-58-EE-A8-D0的形式时就会出错。
假设我的机器MAC是00-15-58-EE-A8-D0,那么由SendARP获取的MAC地址是Int64的数值,转换为字符串后应该是0DA8EE585100,但作为数值转换为字符串后,其前边的0被舍去了,所以就不是12位的字符串,而变成了11位,所以再转换为00-15-58-EE-A8-D0的形式时就会出错。
#5
mark