前言,筆者由于前段時間要做一個MIS系統的開發,由于該MIS為一個非免費軟件,故在完成該系統開發時相應的注冊模塊也須開發,由于為B/S結構的系統,所以在注冊特征碼的選擇上我選擇了獨一無二的網卡MAC地址。閑話少說,下面切入正題。由于該系統屬商業軟件,故以下代碼中僅包含代碼思路,及簡單的實現代碼,具體大家可根據代碼自由發揮,也可與我一起切磋。
'----------------------提取所有網卡的信息--------------------'
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("Scr
SysDir = Split(GlobalMod.GetSysDir, ",")(1)
If InStr(LCase(SysDir), "system32") = 0 Then
GetMacInfo = "本系統只能運行在Nt、Windows 2000、Windows.Net、Windows xp、Windows 2003等32位系統下,不支持32位以下的系統!"
'www.49028c.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")
'定義線程掛起的時間,這里為毫秒
AspSleepThread.SleepTime = 500
AspSleepThread.BeginSleepThread
GetMacInfo = ExecuteOne(FileStr, "Physical Address. . . . . . . . . : (.*)")
Set AspSleepThread = Nothing
Else
GetMacInfo = "系統當前無法獲取您的網絡信息,請檢查權限繼承關系后再運行本系統!"
Exit Function
End If
DelFile MacFile
Set fso = Nothing
End Function
'------------------在字符串匹配一次結果-------------------'
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
代碼中GETMACINFO函數僅僅可以獲取首個網卡的MAC地址,至于DNS、網關等信息大家可以舉一反三啊。
新聞熱點
疑難解答