You could probably get away with using expect. Basically, you could have your script call the expect script in a loop (or figure out how to make expect do a loop) which will be for each machine you want to test. So, make your shell script do a loop, where the variable gets concatenated to a string that is the IP address:
#!/bin/bash
base_ip="10.0.0."
for (( i=1; i<=100; i++ ))
do
newip="${base_ip}$i";
./monkey_bars.exp $newip
done
Then, you have to create the expect script, which I named monkey_bars.exp. If you change the name of the expect script, you'll need to change it in the above bash script as well...anyway, you can expect the expect script to look like this, though, you may want to modify it to behave differently, and catch other outputs that this one neglects:
#!/usr/bin/expect
set timeout 20
set Machine [lindex $argv 0]
spawn -noecho -console telnet $Machine
set log [open monkey.bars a]
expect {
login {puts $log "$Machine UP!";}
-re "Connection refused" {puts $log "$Machine DOWN";}
}
Honestly, the only reason I put this as a possibility, is because you posted this in the shell scripts forum, so you were probably looking for a scripting solution.... however, this is a hack job. The proper way to do this, is with a C++ program, or even perl script, that can be used to create its own sockets. Then, you would do a loop, and iterate over a list of new sockets, and cleanly retrieve the responses into a file. This script solution is buggy, and hacky.... consider what happens when a computer (say 10.0.0.3) is not up and running.... and I don't mean just not running telnet... I mean powered off. The response is different (no route to host) than if it simply was refusing connections. There are a number of other caveats with this method, that would be better solved with an actual application, but this hack-job will get the job done if tweaked just right.
note: The expect script creates a file called "monkey.bars" in the present working directory of the expect script. That file contains the results of the scanned servers.