Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


November 2002

Network-Database Lookups Made Easy

Troubleshoot connectivity problems with a script that queries three network services
RSS
Subscribe to Windows IT Pro | See More Domain Name System (DNS) Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

Using Dhcpcmd to Query DHCP
The code at callout B calls Dhcpcmd to query a specific scope on a specific DHCP server to return the lease information from the database. The generic syntax is

Dhcpcmd DHCPServerIPAddress
  command [command options]

Command options range from one that creates subnets to one that adds reservations. The Enumclients command tells the DHCP server to query the database for IP address lease information. Netlookup uses a DHCP server with the IP address 10.0.1.5 configured with the subnet 10.0.1.0. The -h command option displays the MAC address for each computer along with the lease information. Enumclients returns the entry record number in the database, the IP address leased, and the NetBIOS name of the computer. The query returns all the subnet's leases, so the script redirects the Dhcpcmd output to the variable %dhcpdump%, which Netlookup then filters for information about the computer Niser. At callout C, Netlookup uses the Findstr utility, a helpful text pattern­matching tool, to search for "Niser" in dhcpdump.txt. The -i tells Findstr to ignore case, and %1 represents the parameter Niser that I specified on the call to Netlookup. The results appear on screen, as follows:

10.0.1.15  NISER  a1b2c3d4e5f6

If you have multiple scopes or DHCP servers to search, add them as additional lines in Netlookup. Because the variables Netlookup defines point to text files under the %temp% system variable, you don't have to worry about the location of the Temp directory. In Win2K, %temp% defaults to %userprofile%\Local Settings in the user's profile; in NT, the variable usually points to C:\Temp.

Querying WINS with Winscl
Next, Netlookup searches the WINS database. Winscl is a great tool for looking up information in WINS and an excellent alternative to using the database's time-consuming GUI. When you run Winscl from the command line, the tool prompts you for several responses. Netlookup supplies the responses for you in an answer file embedded in the code at callout D. The code at Callout D echos the header information for the lookupresults file and redirects the text to the Winscl file. Then, Netlookup specifies 1 to tell Winscl that you use TCP/IP (not named pipes) and supplies the NetBIOS name of the WINS server to query. Netlookup then specifies QN (to tell Winscl to query names), %1 to represent the computer name to search for, and 0 to indicate that you don't want to query for specific NetBIOS registrations. Finally, Netlookup uses the EX command to exit the tool.

As it did with the Dhcpcmd results, Netlookup uses Findstr to pick out only the information you need. The code at callout E calls Winscl and Findstr with a pipe symbol between them, which tells the system to run Winscl, then do something with the results. The information you want to filter from the results of Winscl is in two different lines, so Findstr matches two patterns. Two /c switches on the Findstr command pattern-match on text strings that the developer specifies (in this case, Name= and "Address is"). The script redirects the results to lookupresults.txt and adds them to the DHCP query results. Notice the script uses two greater than (>) signs to append the results to the file's existing text. After you run the command, the contents of the lookupresults.txt file appear as follows:

Name=(NISER   ) Address is (10.0.1.15)

You'll find Winscl a bit clunky, but useful. DNS will replace WINS over time, but until it does, the need to manage and understand WINS is as important as ever.

DNS Queries with Nslookup
The DNS database lookup is the easiest of the three database lookups to perform. Netlookup uses the Nslookup utility to query DNS about the computer name you specified when you called Netlookup. The code at callout F calls Nslookup and adds the results to the lookupresults.txt file.

Ping and Results
After Netlookup collects the network-service information, it pings the remote computer to verify that the IP address is accessible (if the user specified the optional -p switch on the command line). Callout G shows the syntax that provides the optional ping.

After the script completes the DHCP, WINS, and DNS queries, the line of code at callout H displays the results to your screen. You can make the lookupresults.txt file easier to read by adding a descriptive Echo statement before each section of code that queries one of the databases. The script's final lines of code clear the Netlookup files.

When you're trying to determine why you can't connect to a specific computer on your network, you want to do it quickly. Various command-line tools are available for querying DHCP, WINS, and DNS, and when you tie them together with a script such as Netlookup, you have a fast and easy way to acquire the information you need all at once.

End of Article

   Previous  1  [2]  Next  


Reader Comments
%winscl.input% should be %winsclinput%

Andrew Plackowski November 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.



Michael Czerwinski November 07, 2002


You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

New Microsoft/Yahoo! Deal? No

On Sunday, the Times of London reported that Microsoft had renewed talks with failing Internet giant Yahoo! and would manage its search engine for 10 years, while Yahoo! would retain control of its email, messaging, and content services. This report ...

How can I stop and start services from the command line?

...


Task Automation Whitepapers Essential Guide to E-discovery and Recovery for Microsoft Exchange

Continuous Data Protection and Recovery for Microsoft Exchange

Protecting (You and) Your Data with Exchange Server 2007

Related Events Implementing VoIP for Your Enterprise

Windows, Unix, Linux Interoperability

Check out our list of Free Email Newsletters!

Task Automation eBooks Spam Fighting and Email Security for the 21st Century

A Guide to Windows Certification and Public Keys

Keeping Your Business Safe from Attack: Patch Management

Related Task Automation Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing