I've written a homegrown tool that automates other command-line tools by using
input data from a text file. My tool is a simple, one-line shell script that
works on Windows, Linux, and Mac OS X with just a few modifications.
How It Works
Let's say you run a firewall report of the top outgoing activity destinations
by users of your network. Unfortunately, the firewall doesn't perform the IP
address-to-name lookup function and instead simply gives you a list of IP addresses
and the number of connections initiated for each address, similar to the information
in Table 1.
This report would become much more interesting (and useful) if the IP addresses were resolved to domain names. Then it would reveal at a glance which users were visiting a portal, streaming music, accessing Web mail, or conducting other types of Internet-based activities.
Several common command-line tools such as Whois, dig, and Microsoft's NBTStat
help you resolve IP addresses to their owners, DNS names, and Windows NetBIOS
names, respectively. It's easy to run Whois for a single address. For example,
typing
whois 66.102.7.99
shows you who owns that IP address. The tool takes a few seconds to run and you need to scroll through the output to find the data you want.
To automate the process of reading a list of objects, such as our firewall-report
IP addresses, from a text file and processing each object through the Whois
command, you can write a wrapper. The first step is to copy the IP addresses
into a text editor, one per line,
66.102.7.99
216.239.63.83
66.94.230.34
207.68.183.35
17.112.152.32
66.102.7.104
66.102.7.147
and save the entries as a text file, with a name like data.txt.
The next step is to create a short script that reads the file, loops through
each item in the file, executes a command targeting each item, and manipulates
the output to improve the presentation. Many systems administrators use Linux
and Mac OS X as well as Windows, so fortunately, it's easy to port this useful
script between platforms. We'll look at the Bourne-Again Shell (BASH) version
of the script first and then the same script as a Windows shell script.
Prev. page  
[1]
2
next page