WSH practical lecture: Lecture 1: Obtaining the network attribute configuration of the machine
Author:Eve Cole
Update Time:2009-05-30 19:53:51
For the original text, please go to WSH (WHITE’s Little Home) (http://wwwasp.yeah.net)
In fact, it is just reading the registry, but if you can obtain the IP configuration and other information of the machine, it will be simple to configure IIS in the future. The following script reads out all available IP addresses of the machine, subnet mask, but omits gateway and other information:
Code:
-------------------------------------------------- ----------------------------------
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" & sNic
& "ParametersTcpip" 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
-------------------------------------------------- ----------------------------------
Note: The machine's network configuration is saved in the registry, under the network card item, so you must first know the name of the network card. Then get the registry data, the IP address and subnet mask are all in array form (in fact, the registry saves binary data, VBSCRIPT helps us convert it). Reading the registry in WSH is very simple, please see the above procedure for details.