精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>● ASP>>ASP范例>>取得服务器端网卡的MAC地址(wscript)

主题:取得服务器端网卡的MAC地址(wscript)
发信人: dbzh()
整理人: qcrsoft(2002-05-09 23:26:53), 站内信件
     <%
Dim Item
%>
     
     <!-- Show greeting using selected server variables -->
     Hello visitor from <%= Request.ServerVariables("REMOTE_ADDR") %>! Your
     browser identifies itself as <%= Request.ServerVariables("HTTP_USER_AGENT") %>.
     
     

     

     
     <!-- Show all server variables -->
     <TABLE BORDER=2>
     <TR>
     <TD>Server Variable</TD>
     <TD>Value</TD>
     </TR>
     <% For Each Item In Request.ServerVariables %> 
     <TR>
     <TD><FONT SIZE="-1"><%= Item %></TD>
     <TD><FONT SIZE="-1"><%= Request.ServerVariables(Item) %> </TD>
     </TR>
     <% Next %>
     </TABLE>
     
     <% ' That's It! Another cool time when a few lines of code go a long way! %>;

    <%
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> 

[关闭][返回]