网友俱乐部 » » ASP教程 » WSH实用讲座:第一讲 获取机器的网络属性配置

2008-5-12 09:10 羽毛の昕
WSH实用讲座:第一讲 获取机器的网络属性配置

原文请到WSH(WHITE的小家)(http://wwwasp.yeah.net )
  其实就是读注册表,不过如果能获得机器的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
("HKLMSOFTWAREMicrosoftWindows NTCurrentVersionNetworkCards1ServiceName") If sTcpipRegKey
<> "Microsoft" And Err.Number = 0 Then   sTcpipRegKey = "HKLMSYSTEMCurrentControlSetServices" &amp; sNic
&amp; "ParametersTcpip"   bIsDHCP = WSHShell.RegRead(sTcpipRegKey &amp; "EnableDHCP")   If bIsDHCP Then   
  Gateway = WSHShell.RegRead(sTcpipRegKey &amp; "DhcpDefaultGateway")     IPAddress = WSHShell.RegRead
(sTcpipRegKey &amp; "DhcpIPAddress")     SubnetMask = WSHShell.RegRead(sTcpipRegKey &amp; "DhcpSubnetMask")  
   MsgBox ("DefaultGateway: " &amp; Gateway(0) &amp; Chr(10) &amp; Chr(13) &amp; "IPAddress: " &amp; IPAddress &amp; Chr(10) &amp;
Chr(13) &amp; "SubnetMask: " &amp; SubnetMask)   Else     Gateway = WSHShell.RegRead(sTcpipRegKey
&amp; "DefaultGateway")     IPAddress = WSHShell.RegRead(sTcpipRegKey &amp; "IPAddress")     SubnetMask =
WSHShell.RegRead(sTcpipRegKey &amp; "SubnetMask")     For i=0 to Ubound(IPAddress)-1       MsgBox
("DefaultGateway: " &amp; Gateway(0) &amp; Chr(10) &amp; Chr(13) &amp; "IPAddress: " &amp; IPAddress(i) &amp; Chr(10) &amp; Chr(13)
&amp; "SubnetMask: " &amp; SubnetMask(i))     Next   End If End If
--------------------------------------------------------------------------------
  说明:机器的网络配置保存在注册表里,网卡项目下面,所以首先必须知道网卡的名字。然后取注册表数据,IP地址和子网掩
码都是数组形式(其实注册表里保存的是二进制数据,VBSCRIPT帮我们转换了)。在WSH里读注册表非常的简单,具体请看上面的
程序。

页: [1]


Powered by Discuz! Archiver 5.5.0  © 2001-2006 Comsenz Inc.