Well I'm not very good at iptables, I'm guessing you know how so I'll leave that for you.
If i understand you correctly you have a list of usernames and password that should somehow be related to the host address?
In that case you can build a list looking like this:
Code:
# cat iplist.txt
10.0.0.1:username:pass
10.0.0.2:username:pass
10.0.0.3:username:pass
10.0.0.4:username:pass
10.0.0.5:username:pass
Code:
#!/bin/bash
# This is just to split strings, it's pretty dumb and just splits by 1 character and no real regexp splitting.
function split {
delim=$1
len=${2//[^$delim]/}
len=${#len}
((len += 1))
for ((b=0;$b < $len; b++)); do
((pos = b + 1));
key=$(echo $2|cut -d$delim -f$pos)
split[$b]=$key
done
}
# Temporary file.
expfile=/tmp/$$.tmp
list=$1
delimiter=$2
[ -z $delimiter ] && delimiter=":"
x=0
# Run throu the list specified above
for i in $(cat $list); do
# Everything splitted ends up in an array named $split
split "$delimiter" $i
host=${split[0]}
user=${split[1]}
pass=${split[2]}
# Use expect to send password :)
echo "
#!/usr/bin/expect
spawn ssh \$argv ifconfig eth0
expect \"$user@$host's password:\"
send \"$pass\\r\"
interact
" > $expfile
result=$(expect $expfile $user@$host | grep -i "inet addr")
# Chopping out the IP from ifconfig output
split ":" "$result"
ip=$(echo "${split[1]}" | cut -d' ' -f1)
# INSERT CODE FOR IPTABLES HERE!
((x++))
done
rm $expfile
This is not fool proof, but afaik SSH does not change it's behaviour when giving you the password prompt.
This also requires Expect software which i believe is standard for most linux distro's

If there is a kolon in any of the password you'll have bit of a problem, you'll have to change the delimeter to something which isn't in any of the strings for host, user or password.
In that case you'll have to add the new delimiter as argument 2 on the shellscript.
Usage: ./script.sh <list-of-ip-user-pass.txt> [<delimiter>]
ps. It's semi tested, not sure how it would do with alot of machines but it works when I try it 2 times against my machine

ds.
Best regards
Fredrik Eriksson