如何获取机器的网络配置属性?
来源:asp之家 时间:2009-11-23 20:44:00
asp使用WScript.Shell获取电脑的网络配置信息
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