The Linux and Mac OS X Version
BASH is the standard command-line shell in Linux and Mac OS X. The script below
loops through the contents of the data.txt file and performs a Whois lookup
on each IP address contained in the file:
for ip in $(cat data.txt); do
whois $ip | echo "$ip $(grep
'OrgName')"; done
This script is a simple loop consisting of three steps separated by semicolons.
The first step sets up a for ... in loop, defines the ip variable
to represent the IP address, and defines a variable to represent the source
of the data. The variable representing the objects to be used is populated by
using the cat command. Specifically, $(cat data.txt) means use
the output of the cat data .txt command—in this case, the list
of IP addresses—as a variable. Cat simply sends the contents of
a text file to output. In summary, for ip in $(cat data.txt) means, "Loop
through every item in the data.txt file and store each one in the variable ip
for immediate processing by the core of the script." . . .
Thanks
tekgeek January 19, 2007 (Article Rating: