使用ASP获得服务器网卡的MAC地址信息

时间:2022-06-29 01:08:34
  1. '----------------------提取所有网卡的信息--------------------'   
  2.  
  3. Public Function GetMacInfo()   
  4.     On Error Resume Next   
  5.  
  6.     Dim fso, FileStr, AspSleepThread, CmdStr, SysDir, wshshell, CmdRe, MacFileContentFile, MacFileContent   
  7.     Const MacFile = "TmpYesoulSoft001.LLP"   
  8.     Set fso = Server.CreateObject("Scripting.FileSystemObject")   
  9.  
  10.     SysDir = Split(GlobalMod.GetSysDir, ",")(1)   
  11.             If InStr(LCase(SysDir), "system32") = 0 Then   
  12.             GetMacInfo = "本系统只能运行在Nt、Windows 2000、Windows.Net、Windows Xp、Windows 2003等32位系统下,不支持32位以下的系统!"   
  13.             Exit Function   
  14.             Else   
  15.             CmdStr = SysDir + "\Cmd.exe /C " + SysDir + "\Ipconfig.exe /All > " + Server.MapPath(MacFile)   
  16.             End If   
  17.         CmdRe = Shell(CmdStr, vbHide)   
  18.         If CmdRe <> 0 Then   
  19.         Set MacFileContentFile = fso.OpenTextFile(Server.MapPath(MacFile), 1, False, TristateUseDefault)   
  20.         'GetMacInfo = MacFileContentFile.ReadAll()   
  21.         'Response.Flush   
  22.         FileStr = MacFileContentFile.ReadAll()   
  23.         MacFileContentFile.Close   
  24.         Set MacFileContentFile = Nothing   
  25.         Set AspSleepThread = Server.CreateObject("YesoulSoft.SleepThread")   
  26.         '定义线程挂起的时间,这里为毫秒   
  27.         AspSleepThread.SleepTime = 500   
  28.         AspSleepThread.BeginSleepThread   
  29.         GetMacInfo = ExecuteOne(FileStr, "Physical Address. . . . . . . . . : (.*)")   
  30.         Set AspSleepThread = Nothing   
  31.         Else   
  32.         GetMacInfo = "系统当前无法获取您的网络信息,请检查权限继承关系后再运行本系统!"   
  33.         Exit Function   
  34.         End If   
  35.         DelFile MacFile   
  36.  
  37.     Set fso = Nothing   
  38.  
  39. End Function   
  40. '------------------在字符串匹配一次结果-------------------'   
  41. Public Function ExecuteOne(inpStr, PatStr)   
  42.   Dim oRe, oMatch, oMatches   
  43.   Set oRe = New RegExp   
  44.   oRe.Pattern = PatStr   
  45.   inpStr = LCase(inpStr)   
  46.   oRe.IgnoreCase = True   
  47.   Set oMatches = oRe.Execute(inpStr)   
  48.   Set oMatch = oMatches(0)   
  49.   ExecuteOne = oMatch.SubMatches(0)   
  50. End Function