asp如何用WSH获取机器的IP配置信息?
时间:2010-06-13 14:39:00
如何用WSH获取机器的IP配置信息?
我们用VBSCRIPT转换了:
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