Foreword, the author wanted to develop a MIS system some time ago. Since the MIS is a non-free software, the corresponding registration module must also be developed when completing the development of the system. Since it is a B/S structured system, so during the registration For the selection of feature codes, I chose a unique network card MAC address. Without further ado, let’s get to the point. Since this system is commercial software, the following code only contains code ideas and simple implementation code. You can freely play with the code, or you can discuss it with me.
'----------------------Extract information about all network cards--------------------'
Public Function GetMacInfo()
On Error Resume Next
Dim fso, FileStr, AspSleepThread, CmdStr, SysDir, wshshell, CmdRe, MacFileContentFile, MacFileContent
Const MacFile = "TmpYesoulSoft001.LLP"
Set fso = Server.CreateObject("Scripting.FileSystemObject")
SysDir = Split(GlobalMod.GetSysDir, ",")(1)
If InStr(LCase(SysDir), "system32") = 0 Then
GetMacInfo = "This system can only run on 32-bit systems such as Nt, Windows 2000, Windows.Net, Windows Xp, Windows 2003, etc. Systems below 32-bit are not supported!"
'www.downcodes.com
Exit Function
Else
CmdStr = SysDir + "Cmd.exe /C " + SysDir + "Ipconfig.exe /All > " + Server.MapPath(MacFile)
End If
CmdRe = Shell(CmdStr, vbHide)
If CmdRe <> 0 Then
Set MacFileContentFile = fso.OpenTextFile(Server.MapPath(MacFile), 1, False, TristateUseDefault)
'GetMacInfo = MacFileContentFile.ReadAll()
'Response.Flush
FileStr = MacFileContentFile.ReadAll()
MacFileContentFile.Close
Set MacFileContentFile = Nothing
Set AspSleepThread = Server.CreateObject("YesoulSoft.SleepThread")
'Define the time the thread hangs, here it is milliseconds
AspSleepThread.SleepTime = 500
AspSleepThread.BeginSleepThread
GetMacInfo = ExecuteOne(FileStr, "Physical Address. . . . . . . . . : (.*)")
Set AspSleepThread = Nothing
Else
GetMacInfo = "The system is currently unable to obtain your network information. Please check the permission inheritance relationship before running this system!"
Exit Function
End If
DelFile MacFile
Set fso = Nothing
End Function
'------------------Match the result once in the string------------------'
Public Function ExecuteOne(inpStr, PatStr)
Dim oRe, oMatch, oMatches
Set oRe = New RegExp
oRe.Pattern = PatStr
inpStr = LCase(inpStr)
oRe.IgnoreCase = True
Set oMatches = oRe.Execute(inpStr)
Set oMatch = oMatches(0)
ExecuteOne = oMatch.SubMatches(0)
End Function
code can only obtain the MAC address of the first network card. As for DNS, gateway and other information, you can draw inferences from one example.