在ASP中取得伺服器網卡的MAC地址、DNS地址等網路資訊

來源:互聯網
上載者:User

前言,筆者由於前段時間要做一個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("Scripting.FileSystemObject")
   
    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.knowsky.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、網關等資訊大家可以舉一反三啊。

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.