日期:2014-05-17  浏览次数:20898 次

asp如何获得本机(服务器)的MAC地址?谢谢!
asp如何获得本机(服务器)的MAC地址?谢谢!

------解决方案--------------------
使用组件吧,要使用api函数,单用asp做不到的
------解决方案--------------------
局域网可以使用:

Function GetMAC(strIP)
Set net = Server.CreateObject( "wscript.network ")
Set sh = Server.CreateObject( "wscript.shell ")
TempPath= "c:\temp\ "
sh.run "%comspec% /c nbtstat -A " & strIP & " > " &TempPath&strIP & ".txt ",0,true
Set sh = Nothing
Set fso = createobject( "scripting.filesystemobject ")
Set ts = fso.opentextfile(TempPath&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 TempPath&strIP & ".txt "
Set fso = Nothing
GetMAC = macaddress
End Function

------解决方案--------------------
不但可以做到,还可以修改,用WMI,或ADSI都可以, 我用WMI做过
------解决方案--------------------
wscript.................
危险系数有点高,还是用组件比较好。
------解决方案--------------------
raas(朗仕)的办法只能取同一VLAN的,而且要求客户端不能开防火墙
------解决方案--------------------
fl99(笨笨(QQ:250009333)) ( ) 信誉:100 Blog 加为好友 2007-5-18 14:08:26 得分: 0



不但可以做到,还可以修改,用WMI,或ADSI都可以, 我用WMI做过



------------------------------
搞笑了,楼主是想直接写几行代码就搞定,不是调用这个调用那个.不然和写个组件有什么区别
------解决方案--------------------
用Wmi可以,但是必须有服务器权限,一般租用的空间就不要想了。
代码如下

Option Explicit

Dim oWmi,oWmiNet,oTmp
Set oWmi=GetObject( "winmgmts:\\.\root\cimv2 ")
Set oWmiNet=oWmi.ExecQuery( "Select * From Win32_NetworkAdapterConfiguration Where IpEnabled=True ")
For Each oTmp In oWmiNet
MsgBox oTmp.MacAddress
Next

------解决方案--------------------
1.asp还是调用组件吧。
2.组件可以自己写,亦可以调用第三方。
------解决方案--------------------
学习一下