asp获取机器的网络属性配置
发表于:2007-06-30来源:作者:点击数:
标签:
其实就是读注册表,不过如果能获得机器的IP配置等信息,以后配置IIS时就简单了。 下面的脚本读出机器的所有可用IP地址,子网掩码,却省网关等信息: Option Explicit Dim WSHShell Dim sNic, sMan Dim Gateway Dim IPAddress Dim Su .net Mask Dim i Dim sTcp
其实就是读注册表,不过如果能获得机器的IP配置等信息,以后配置IIS时就简单了。
下面的脚本读出机器的所有可用IP地址,子网掩码,却省网关等信息:
Option Explicit
Dim WSHShell
Dim sNic, sMan
Dim Gateway
Dim IPAddress
Dim Su
.netMask
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里读注册表非常的简单,具体
请看上面的程序。
原文转自:http://www.ltesting.net