ssh is easier than telnet:
for host in host1 host2 host3; do ssh user@host remote_command with args done > result.file
For password-less login, set up ssh keys
This will have bugs, but something like:
#!/usr/bin/env expect exp_internal 1 set out [open "results.txt" w] foreach ip $argv { spawn telnet $ip expect "password: " send "$password\r" expect "% " ;# this is the prompt, adjust to suit sent "the command\r" expect -re "([01,]+).*% " puts $out "$ip=$expect_out(1,string)" send exit expect eof exp_close wait } close $out