asp擷取機器的網路屬性配置

來源:互聯網
上載者:User
網路 其實就是讀註冊表,不過如果能獲得機器的IP配置等資訊,以後配置IIS時就簡單了。
下面的指令碼讀出機器的所有可用IP地址,子網路遮罩,卻省網關等資訊:

Option Explicit
Dim WSHShell
Dim sNic, sMan
Dim Gateway
Dim IPAddress
Dim SubnetMask
Dim i

Dim sTcpipRegKey
Dim bIsDHCP

Set WSHShell = CreateObject("WScript.Shell")

sNic = WSHShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\
CurrentVersion\NetworkCards\1\ServiceName")

If sTcpipRegKey <> "Microsoft" And Err.Number = 0 Then

sTcpipRegKey = "HKLM\SYSTEM\CurrentControlSet\Services\"
& sNic & "\Parameters\Tcpip\"

bIsDHCP = WSHShell.RegRead(sTcpipRegKey & "EnableDHCP")
If bIsDHCP Then
Gateway = WSHShell.RegRead(sTcpipRegKey & "DhcpDefaultGateway")
IPAddress = WSHShell.RegRead(sTcpipRegKey & "DhcpIPAddress")
SubnetMask = WSHShell.RegRead(sTcpipRegKey & "DhcpSubnetMask")
MsgBox ("DefaultGateway: " & Gateway(0) & Chr(10) & Chr(13)
& "IPAddress: " & IPAddress & Chr(10) & Chr(13) & "SubnetMask: " & SubnetMask)
Else
Gateway = WSHShell.RegRead(sTcpipRegKey & "DefaultGateway")
IPAddress = WSHShell.RegRead(sTcpipRegKey & "IPAddress")
SubnetMask = WSHShell.RegRead(sTcpipRegKey & "SubnetMask")
For i=0 to Ubound(IPAddress)-1
MsgBox ("DefaultGateway: " & Gateway(0) & Chr(10) & Chr(13)
& "IPAddress: " & IPAddress(i) & Chr(10) & Chr(13) & "SubnetMask: "
& SubnetMask(i))
Next
End If
End If

說明:機器的網路設定儲存在註冊表裡,網卡項目下面,所以首先必須知道網卡的名字。然後取註冊表資料,IP地址和子
網掩碼都是數組形式(其實註冊表裡儲存的是位元據,VBSCRIPT幫我們轉換了)。在WSH裡讀註冊表非常的簡單,具體
請看上面的程式。 



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.