获得客房端的MAC(Media Access Control)地址

本文介绍了一种使用VBScript获取客户端MAC地址的方法。通过创建WScript.Network对象和WScript.Shell对象,结合命令行工具nbstat来获取指定IP地址的MAC地址。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<a href='http://www.biancheng88.cn/html/2008-11/MAC-15647052.html'>获得客房端的MAC(Media Access Control)地址</a><br><br>
                  Get the clients <a href="http://www.biancheng88.cn/html/special/2008-11/MAC/" title="MAC" target=_blank><B>MAC</B></a>(Media Access Control) address, a hardware address that uniquely identifies each <br>
node of a network. Works great on LAN's. Firewalls and Proxy's will be an issue depending what side of <br>
them you're coding for. <br>
<br>
<br>
  <br>
Can't Copy and Paste this?<br>
Click here for a copy-and-paste friendly version of this code!<br>
<br>
<br>
<br>
    '**************************************<br>
    ' for :<a href="http://www.biancheng88.cn/html/special/2008-11/MAC/" title="MAC" target=_blank><B>MAC</B></a> address<br>
    '**************************************<br>
    This code is AS IS! I had a need For it on a <br>
    project I was working On and found almost no info <br>
    anywhere On what I needed To accomplish. If it <br>
    helps you, great! If it does Not work For you: <br>
    1.Make sure you're Not trying To hit on the same <br>
    pc it's on.<br>
    2.Comment out where the file gets deleted <br>
    (fso.deletefile "c:/" & strIP & ".txt"), To view <br>
    some potential Error info.<br>
    3.Have fun debugging :) (I did)<br>
<br>
<br>
code:<br>
Can't Copy and Paste this?<br>
Click here for a copy-and-paste friendly version of this code!<br>
<br>
<br>
<br>
    '**************************************<br>
    ' Name: <a href="http://www.biancheng88.cn/html/special/2008-11/MAC/" title="MAC" target=_blank><B>MAC</B></a> address<br>
    ' Description:Get the clients MAC(Media <br>
    '     Access Control) <br>
    address, a hardware address that uniquely <br>
    identifies Each node of a network. Works great on <br>
    LAN's. Firewalls and Proxy's will be an issue <br>
    depending what side of them you're coding for.<br>
    ' By: Jerry Aguilar<br>
    '<br>
    '<br>
    ' Inputs:None<br>
    '<br>
    ' Returns:Returns the client IP and MAC <br>
    '     address.<br>
    '<br>
    'Assumes:You can't navigate to it runnin<br>
    '     g PWS on the same<br>
    pc but If you are running PWS, you can navigate <br>
    To it from another pc on the same lan (it does <br>
    Not like 127.0.0.1)<br>
    '<br>
    'Side Effects:None<br>
    '<br>
    'Warranty:<br>
    'code provided by Planet Source Code(tm)<br>
    '     (www.Planet-Source-Code.com) 'as is', wi<br>
    '     thout warranties as to performance, fitn<br>
    '     ess, merchantability,and any other warra<br>
    '     nty (whether expressed or implied).<br>
    'Terms of Agreement:<br>
    'By using this source code, you agree to<br>
    '     the following terms...<br>
    ' 1) You may use this source code in per<br>
    '     sonal projects and may compile it into a<br>
    '     n .exe/.dll/.ocx and distribute it in bi<br>
    '     nary format freely and with no charge.<br>
    ' 2) You MAY NOT redistribute this sourc<br>
    '     e code (for example to a web site) witho<br>
    '     ut written permission from the original <br>
    '     author.Failure to do so is a violation o<br>
    '     f copyright laws.<br>
    ' 3) You may link to this code from anot<br>
    '     her website, provided it is not wrapped <br>
    '     in a frame.<br>
    ' 4) The author of this code may have re<br>
    '     tained certain additional copyright righ<br>
    '     ts.If so, this is indicated in the autho<br>
    '     r's description.<br>
    '**************************************<br>
    <br>
    <%@ LANGUAGE="VBSCRIPT"%><br>
    <%<br>
     strIP = Request.ServerVariables("REMOTE_ADDR")<br>
     strMac = GetMACAddress(strIP)<br>
     strHost = Request.ServerVariables("REMOTE_HOST")<br>
    Function GetMACAddress(strIP)<br>
    Set net = Server.CreateObject("wscript.network")<br>
    Set sh = Server.CreateObject("wscript.shell")<br>
    sh.run "%comspec% /c nbtstat -A " & strIP & " > c:/" & strIP & ".txt",0,true<br>
    Set sh = nothing<br>
    Set fso = createobject("scripting.filesystemobject")<br>
    Set ts = fso.opentextfile("c:/" & strIP & ".txt")<br>
    macaddress = null<br>
    Do While Not ts.AtEndOfStream<br>
    data = ucase(trim(ts.readline))<br>
    If instr(data,"MAC ADDRESS") Then<br>
    macaddress = trim(split(data,"=")(1))<br>
    Exit Do<br>
    End If<br>
    loop<br>
    ts.close<br>
    Set ts = nothing<br>
    fso.deletefile "c:/" & strIP & ".txt"<br>
    Set fso = nothing<br>
    Get<a href="http://www.biancheng88.cn/html/special/2008-11/MAC/" title="MAC" target=_blank><B>MAC</B></a>Address = macaddress<br>
    End Function <br>
    %><br>
    <HTML><br>
    <HEAD><br>
    <TITLE>Say Hello To the MAC MAN</TITLE><br>
    </HEAD><br>
    <BODY><br>
    <%Response.Write("Your IP is : " & strIP & "<BR>" & vbcrlf)%><br>
    <%Response.Write("Your <a href="http://www.biancheng88.cn/html/special/2008-11/MAC/" title="MAC" target=_blank><B>MAC</B></a> is : " & strMac & vbcrlf)%><br>
    </BODY><br>
    </HTML>  <br>
 <br>

                 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值