So last month
I left you hanging on the idea that there are some strong mojo,
super secret miracle approaches to making Windows systems manageable, secure
and reliable. As we go along, the goal we'll be working toward is removing the
mystery and making Windows systems as obvious as they are supposed to be. It's
important to note, though, that we will fail to achieve this goal and that failure
will not be all that important in the long run.
Before you can make decisions with any valuable impact, it's usually important
to get information pertinent to your problem. NT based systems offer a number
of utilities out of the box that can be handy for getting useful information
about any number of system aspects. But instead of showing you how to use utilities
like netstat, nbtstat and ping, let's get involved hip deep in something that
is more flexible and that begins to allow you to develop shell depth similar
to that enjoyed by Unix operators; scripting.
The Tools to Start With
Specifically, the Windows Script Host (WSH) and VBScript will be used to gather
information that will help you make decisions. I'm not going to teach you to
program or to understand WSH. To do so would be a terrible waste of time and
space. The best way to get familiar with WSH and what it can do is to visit
and read!! Download the WSH help files and use them as a reference. They actually
are quite useful and have many examples to work from. If you need a paper reference,
allow me to suggest that "Windows Script Host 2.0" by Dino Esposito,
WROX Press is an excellent source. It is well written, has pretty good examples
and is light enough to be used as a pocket reference. Note that it is older
than the current version of WSH but the information it contains is still valid.
Next, read some of Andrew Clinick's work at the above site. Mr. Clinick has
a way of demonstrating some tough ideas in useful ways. He and his crew are
definitely on your side, competing on behalf of administrators to deliver useful
tools and the same respect is delivered to the end user of your systems.
Once you've played with some of the examples there, come back here. What I
write won't be any more or less helpful but it will be different. Once you've
gotten used to the idea of what's going on you can also find more information
from the Microsoft public newsgroups. Using an NNTP newsreader like Forte' Agent
, you can get answers to your questions about these scripting technologies from
Microsoft Engineers and other users who, believe it or not, have probably already
had to solve your problem for their own efforts.
Put Up or Shut Up, Administrator
Here's an example script that uses another technology, called Windows Management
Instrumentation (WMI) along with WSH and VBScript to determine what the IP characteristics
of each network adapter is on the local computer. Documentation on the WMI interfaces
is available in the WMI SDK available from Microsoft at http://msdn.microsoft.com/downloads/default.asp?URL=/code/sample.asp?url=/msdn-files/027/001/566/msdncompositedoc.xml
and a tutorial is available at http://msdn.microsoft.com/downloads/default.asp?URL=/code/sample.asp?url=/msdn-files/027/001/574/msdncompositedoc.xml.
Here's the code:
'Support Site: http://www.mousetrax.com
'Author: Greg Chapman
'Force Declaration of Variables
Dim j, NIC1, Nic, StrNic, lngCount, StrIP, i ,objNet,objHost
'If something fails, move on
On Error Resume Next
'Get the Computer's network name
Wscript.Echo "Analysis of " & objHost & "."
'Get a connection to the WMI NetAdapteConfig object
Set NIC1 = GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
'For Each of the NICs in the connection
For Each Nic in NIC1
'Get the Adapter Description
StrNIC = Nic.Description
'If IP is enabled on the NIC then let's find out
about the NIC
IF Nic.IPEnabled THEN
For i=0 to lngCount
If i >= 0 Then
StrNic & vbNewLine
StrIP = vbTab
If StrIP <>
vbTab & "IP Address = " & _
WScript.Echo vbTab & "MAC Address = " & _
vbTab & "NIC Service (Short) Name = " & _
vbTab & "IP Subnet(s): "
For j = 0 to UBound(Nic.IPSubnet)
vbTab & vbTab & Nic.IPSubnet(j)
Wscript.Echo vbTab & "Internet Database Files Path = " & _
vbTab & "Dead Gateway Detection = " & _
vbTab & "IP Gateway(s): "
For j=0 to UBound(Nic.DefaultIPGateway)
Wscript.Echo vbTab & vbTab & Nic.DefaultIPGateway(j)
vbTab & "DHCP Assigned IP address = " & _
vbTab & "DHCP Server = " & _
vbTab & "DNS for WINS Resolution Enabled = " & _
vbTab & "DNS Host Name = " & _
vbTab & "DNS Servers:"
j=0 to UBound(Nic.DNSServerSearchOrder)
vbTab & vbTab & Nic.DNSServerSearchOrder(j)
vbTab & "IP Port Filtering Enabled = " & _
WScript.Echo vbTab & "IP Filtering Enabled."
If Nic.IPSecPermitIPProtocols <> 0 Then
For j=0 to UBound(Nic.IPSecPermitIPProtocols)
vbTab & vbTab & "Protocol: " & _
vbTab & vbTab & "No Protocols Filtered"
Nic.IPSecPermitTCPPorts <> 0 Then
For j=0 to UBound(Nic.IPSecPermitTCPPorts)
vbTab & vbTab & "TCP Port: " & _
vbTab & vbTab & "No TCP Ports Filtered"
Nic.IPSecPermitUDPPorts <> 0 Then
j=0 to UBound(Nic.IPSecPermitUDPPorts)
vbTab & vbTab & "UDP Port: " & _
vbTab & vbTab & "No UDP Ports Filtered"
vbTab & "LMHOSTS Lookup Enabled = " & _
vbTab & "WINS Lookup File = " & _
vbTab & "Primary WINS Server = " & _
vbTab & "Secondary WINS Server = " & _
vbTab & "WINS Scope ID = " & Nic.WINSScopeID
To run the script, copy and paste it to a text document and call it GetNics.vbs.
Then, open a command prompt and type the following:
Or, to create a text file from the output, add this to the end of the above command:
On the screen, the output will resemble that of typing IPConfig /all .
Here's a clip of what my laptop produces when connected to my home network:
Analysis of CHAPPIESLAPPIE.
ORiNOCO Wireless LAN PC Card (5 volt) - Cisco Systems VPN Adapter
IP Address = 192.168.0.102
MAC Address = 00:02:2D:2C:A4:77
NIC Service (Short) Name = wlluc48
Internet Database Files Path = %SystemRoot%\System32\drivers\etc
Dead Gateway Detection =
DHCP Assigned IP address = True
DHCP Server = 192.168.0.3
DNS for WINS Resolution Enabled = False
DNS Host Name = chappieslappie
IP Port Filtering Enabled = False
LMHOSTS Lookup Enabled = False
WINS Lookup File =
Primary WINS Server = 192.168.0.3
Secondary WINS Server =
WINS Scope ID =
Yeah, So What's Your Point?
So why is that so valuable? Because you can get this information, as little
or as much as you want for each NIC and log it. With a few modifications, this
script can produce output that can be sent to a central database or to a configuration
log repository to identify all the systems in your network and how your central systems are managing them.
Central database? Configuration log repository?
Remember that we are working on a way to provide accountability and centralized
management comparable to what a Unix administrator expects at his Solaris console.
Those folks love logs and for good reason! Logs are data and that data is a
checkpoint in the history of a network and its systems. This kind of data allows
an administrator to look for inconsistencies in the network or to analyze the
state of the systems on a network.
When the boss comes along and wants a report of how many systems were on the
network on the 4th of January of this year, the administrator has absolutely
no problem determining several pieces of information the boss is really asking
for. For example, the administrator knows how many addresses were consumed in
each subnet, how many machines total were up and running, whether any of them
have incorrect DNS or WINS server assignments and whether any of them have
invalid IP Filter blocks set.
That logging and accountability capability is important and doing it across
the network instead of visiting 4,000 machines spread all over the world is
what ensures that particular administrator will be the one getting promotions and building