#!/bin/bash


ip_list=${1:?'please the ip list!'}
sum=$(cat $1 | wc -l )
j=1

#recycle
for i in `cat $1`
do
ip=$(echo "$i"|cut -f1 -d":")
password=$(echo "$i"|cut -f2 -d":")
echo "##########process percent:"$j"/"$sum"##########"
let j=j+1

dns_info=$(expect -c"
set timeout 1
spawn ssh  root@$ip \"cat /etc/resolv.conf | grep nameserver\"
        expect {
                \"*yes/no*\" {send \"yes\r\"; exp_continue}
                \"*yes/no*\" {send \"yes\r\"; exp_continue}
                \"*password*\" {send \"$password\r\"; exp_continue}
                \"*Password*\" {send \"$password\r\"}
               }
")

dns_log=$(echo  "$dns_info" | grep nameserver | sed /spawn/d)

#print
echo -e "$ip\n$dns_log"

#record into a file
cat << eof >>dns_info.log
host $ip
$dns_log
***************************
eof

done