Subscribe to Windows IT Pro
October 21, 2002 12:00 AM

Network-Database Lookups Made Easy

Troubleshoot connectivity problems with a script that queries three network services
Windows IT Pro
InstantDoc ID #26693
Rating: (0)
Downloads
26693.zip

I'm always looking for tools to simplify my job as a systems administrator. Sometimes those administrative tools are available from a third-party vendor; sometimes I need to create them. Many of the tools I create are scripts that run from the command line—nothing fancy, but they do what I need. Learning administrative scripting is crucial because of the limitations of many Windows-based administration tools: Scripting provides customization that prebuilt solutions often can't. (For more information about command-line tools for account management, see "Take Command of Your Management Tasks," February 2001, InstantDoc ID 16426).

I created a script a few years ago that continues to be one of the most helpful pieces of code I've written. I developed the script to help me troubleshoot network connectivity problems because I was tired of manually looking up information about a remote workstation or server in the following network-service databases:

  • DHCP server. This server stores IP reservations, assigns dynamic IP addresses, and hands out machine configuration information. The DHCP server database stores the computer name and network adapter media access control (MAC) address of each computer on the network.
  • DNS. DNS provides the lookup mechanism for matching a Fully Qualified Domain Name (FQDN) to an IP address.
  • WINS. WINS servers resolve NetBIOS names to IP addresses. Windows clients register with WINS servers to share their NetBIOS name, MAC address, and NetBIOS registration information.

Querying all these databases for network information is a time-consuming task. My code uses command-line tools and scripting techniques to create an all-in-one lookup tool that returns information about a specific computer.

The Right Tools for the Job
Three tools let you query the network-services databases: Dhcpcmd, for DHCP; Winscl, for WINS; and Nslookup, for DNS. The first two tools, Dhcpcmd and Winscl, are both available in the Windows NT 4.0 Resource Kit Support Tools at http://www.microsoft.com/ntserver/nts/downloads/recommended/ntkit/default.asp (Winscl is also available with the Microsoft Windows 2000 Resource Kit CD-ROM). Nslookup is included with the Win2K and NT OSs.

My script, netlookup.bat (which Listing 1, page 58, shows), has three major sections, each of which uses one of these tools to perform a lookup of one of the network-services databases. The script then redirects the results of those lookups to a text file that you can display on screen. When you run the script from the command line, you provide as the first parameter the name of the computer about which you want information. For example, to query for information about a machine named Niser, you would type

Netlookup niser

at the command line. You might want to copy the query tools into one directory or make sure they're part of your system path so that netlookup.bat can easily find them. Also, each utility needs appropriate permissions to access each database.

The code at callout A in Listing 1 defines variables for the temporary files the script uses: dhcpdump stores the results of the DHCP query, lookupresults holds the data gathered during the script's execution, and winsclinput stores the WINS input file.

Related Content:

ARTICLE TOOLS

Comments
  • Michael Czerwinski
    10 years ago
    Nov 07, 2002

    Great script... love it!!! I noticed some problems with the script when I was trying to use it. After modifications I was able to get it to function in my environment. I added another options that allows you to search in different dns zones. If you wish to see the modified script just email me at email@mikeyski.com.

  • Andrew Plackowski
    10 years ago
    Nov 07, 2002

    %winscl.input% should be %winsclinput%

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.