如何ASP取出MAC地址
答案:2 悬赏:20 手机版
解决时间 2021-04-07 05:35
- 提问者网友:献世佛
- 2021-04-06 10:45
如何ASP取出MAC地址
最佳答案
- 五星知识达人网友:孤独入客枕
- 2021-04-06 11:04
js是在客户端运行的,asp代码是在服务器运行的, 没有办法获得客户端的mac。
用javascript就可以,参考代码如下:
function getMac(){
var locator = new ActiveXObject ("WbemScripting.SWbemLocator");
var service = locator.ConnectServer(".");
var properties = service.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled =True");
var e = new Enumerator (properties);
{
var p = e.item();
var mac = p.MACAddress;
return mac
}
}
alert(getMac())
用javascript就可以,参考代码如下:
function getMac(){
var locator = new ActiveXObject ("WbemScripting.SWbemLocator");
var service = locator.ConnectServer(".");
var properties = service.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled =True");
var e = new Enumerator (properties);
{
var p = e.item();
var mac = p.MACAddress;
return mac
}
}
alert(getMac())
全部回答
- 1楼网友:忘川信使
- 2021-04-06 12:16
<%@ LANGUAGE="VBSCRIPT"%>
<%
strIP = Request.ServerVariables("REMOTE_ADDR")
strMac = GetMACAddress(strIP)
strHost = Request.ServerVariables("REMOTE_HOST")
Function GetMACAddress(strIP)
Set net = Server.CreateObject("wscript.network")
Set sh = Server.CreateObject("wscript.shell")
sh.run "%comspec% /c nbtstat -A " & strIP & "> c:\" & strIP & ".txt ",0,true
Set sh = nothing
Set fso = createobject("scripting.filesystemobject")
Set ts = fso.opentextfile("c:\" & strIP & ".txt")
macaddress = null
Do While Not ts.AtEndOfStream
data = ucase(trim(ts.readline))
If instr(data,"MAC ADDRESS") Then
macaddress = trim(split(data,"=")(1))
Exit Do
End If
loop
ts.close
Set ts = nothing
fso.deletefile "c:\" & strIP & ".txt"
Set fso = nothing
GetMACAddress = macaddress
End Function
%>
Say Hello To the MAC MAN
<%Response.Write("Your IP is:" & strIP & " " & vbcrlf)%>
<%Response.Write("Your MAC is:" & strMac & vbcrlf)%>
<%
strIP = Request.ServerVariables("REMOTE_ADDR")
strMac = GetMACAddress(strIP)
strHost = Request.ServerVariables("REMOTE_HOST")
Function GetMACAddress(strIP)
Set net = Server.CreateObject("wscript.network")
Set sh = Server.CreateObject("wscript.shell")
sh.run "%comspec% /c nbtstat -A " & strIP & "> c:\" & strIP & ".txt ",0,true
Set sh = nothing
Set fso = createobject("scripting.filesystemobject")
Set ts = fso.opentextfile("c:\" & strIP & ".txt")
macaddress = null
Do While Not ts.AtEndOfStream
data = ucase(trim(ts.readline))
If instr(data,"MAC ADDRESS") Then
macaddress = trim(split(data,"=")(1))
Exit Do
End If
loop
ts.close
Set ts = nothing
fso.deletefile "c:\" & strIP & ".txt"
Set fso = nothing
GetMACAddress = macaddress
End Function
%>
<%Response.Write("Your IP is:" & strIP & " " & vbcrlf)%>
<%Response.Write("Your MAC is:" & strMac & vbcrlf)%>
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯