如何在asp中获得MAC地址?

luckydoglau 2003-08-21 02:48:00
同上。
...全文
233 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
Tonglu 2003-08-22
  • 打赏
  • 举报
回复
什么错误?有没有显示帖出来看看
luckydoglau 2003-08-22
  • 打赏
  • 举报
回复
awaysrain(绝对零度) 的代码在本地可以得到Mac地址,但是在服务器上运行的时候就不起作用了。
sailor001 2003-08-22
  • 打赏
  • 举报
回复
使用WSH,但是要有足够的权限
Tonglu 2003-08-22
  • 打赏
  • 举报
回复
是不是也是权限不够?
gboy2003 2003-08-22
  • 打赏
  • 举报
回复
up
nowfox 2003-08-22
  • 打赏
  • 举报
回复
我曾经也用过这段代码,在我机子上运行好好的,在虚拟主机上就不能运行,好像是某个组件被限制啦
luckydoglau 2003-08-21
  • 打赏
  • 举报
回复
不明白为什么mac地址没有显示出来
Tonglu 2003-08-21
  • 打赏
  • 举报
回复
<%@ 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
%>
<HTML>
<HEAD>
<TITLE>Say Hello To the MAC MAN</TITLE>
</HEAD>
<BODY>
<%Response.Write("Your IP is : " & strIP & "" & vbcrlf)%>
<%Response.Write("Your MAC is : " & strMac & vbcrlf)%>
</BODY>
</HTML>

js

<HTML>
<HEAD>
<SCRIPT LANGUAGE=JScript>
var address = new Array()
var i = 0
var wsh = new ActiveXObject("WScript.Shell")
var fso = new ActiveXObject("Scripting.FileSystemObject")
wsh.Run("cmd /C ipconfig /all > c:\\temp.txt", 0)

function getMacAddress() {
var file = fso.OpenTextFile("c:\\temp.txt", 1)
var currentLine
var colon
while(file.AtEndOfStream != true)
{
currentLine = file.ReadLine()
if(currentLine.indexOf("Physical Address") >= 0)
{
colon = currentLine.indexOf(":")
address[i] = currentLine.substr(colon + 1)
i++
}
}
file.Close()
f = fso.GetFile("c:\\temp.txt");
f.Delete();
}
function writeAddress() {
for(j = 0; j < i; j++)
{
mac.innerHTML = mac.innerHTML + " <BR>Mac Address: " + address[j]
}
}
</SCRIPT>

<TITLE></TITLE>
</HEAD>
<BODY>
<P id=mac>
</P>
<Input type="Button" Value="Retrieve Mac Addresses" onClick="getMacAddress()">
<Input type="Button" Value="Display Addresses" onClick="writeAddress()">
</BODY>
</HTML>
awaysrain 2003-08-21
  • 打赏
  • 举报
回复
上面的代码有好多多余的的空格,你把他都去掉就可以了

<%@ 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
%>
<HTML>
<HEAD>
<TITLE>Say Hello To the MAC MAN </TITLE>
</HEAD>
<BODY>
<%Response.Write("Your IP is:" & strIP & " " & vbcrlf)%>
<%Response.Write("Your MAC is:" & strMac & vbcrlf)%>
</BODY>
</HTML>
luckydoglau 2003-08-21
  • 打赏
  • 举报
回复
报错,说GetMACAddress类型不匹配
tonnycncn 2003-08-21
  • 打赏
  • 举报
回复
<%@ 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
% >
<HTML >
<HEAD >
<TITLE >Say Hello To the MAC MAN </TITLE >
</HEAD >
<BODY >
<%Response.Write( "Your IP is : " & strIP & " " & vbcrlf)% >
<%Response.Write( "Your MAC is : " & strMac & vbcrlf)% >
</BODY >
</HTML >
ttt2 2003-08-21
  • 打赏
  • 举报
回复
在网上找一段程序是显示mac地址的,然后把他编译成dll,在asp中调用

但得到的地址是服务器端的
lang11zi 2003-08-21
  • 打赏
  • 举报
回复
没有这服务器环境变量

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧