mabs.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # Blog: http://blog.linuxeye.com
  4. ###################### proc defination ########################
  5. # ignore rule
  6. ignore_init()
  7. {
  8. # ignore password
  9. array_ignore_pwd_length=0
  10. if [ -f ./ignore_pwd ]; then
  11. while read IGNORE_PWD
  12. do
  13. array_ignore_pwd[$array_ignore_pwd_length]=$IGNORE_PWD
  14. let array_ignore_pwd_length=$array_ignore_pwd_length+1
  15. done < ./ignore_pwd
  16. fi
  17. # ignore ip address
  18. array_ignore_ip_length=0
  19. if [ -f ./ignore_ip ]; then
  20. while read IGNORE_IP
  21. do
  22. array_ignore_ip[$array_ignore_ip_length]=$IGNORE_IP
  23. let array_ignore_ip_length=$array_ignore_ip_length+1
  24. done < ./ignore_ip
  25. fi
  26. }
  27. show_version()
  28. {
  29. echo "version: 1.0"
  30. echo "updated date: 2014-06-08"
  31. }
  32. show_usage()
  33. {
  34. echo -e "`printf %-16s "Usage: $0"` [-h|--help]"
  35. echo -e "`printf %-16s ` [-v|-V|--version]"
  36. echo -e "`printf %-16s ` [-l|--iplist ... ]"
  37. echo -e "`printf %-16s ` [-c|--config ... ]"
  38. echo -e "`printf %-16s ` [-t|--sshtimeout ... ]"
  39. echo -e "`printf %-16s ` [-T|--fttimeout ... ]"
  40. echo -e "`printf %-16s ` [-L|--bwlimit ... ]"
  41. echo -e "`printf %-16s ` [-n|--ignore]"
  42. }
  43. IPLIST="iplist.txt"
  44. CONFIG_FILE="config.txt"
  45. IGNRFLAG="noignr"
  46. SSHTIMEOUT=100
  47. SCPTIMEOUT=2000
  48. BWLIMIT=1024000
  49. [ ! -e 'logs' ] && mkdir logs
  50. TEMP=`getopt -o hvVl:c:t:T:L:n --long help,version,iplist:,config:,sshtimeout:,fttimeout:,bwlimit:,log:,ignore -- "$@" 2>/dev/null`
  51. [ $? != 0 ] && echo -e "\033[31mERROR: unknown argument! \033[0m\n" && show_usage && exit 1
  52. eval set -- "$TEMP"
  53. while :
  54. do
  55. [ -z "$1" ] && break;
  56. case "$1" in
  57. -h|--help)
  58. show_usage; exit 0
  59. ;;
  60. -v|-V|--version)
  61. show_version; exit 0
  62. ;;
  63. -l|--iplist)
  64. IPLIST=$2; shift 2
  65. ;;
  66. -c|--config)
  67. CONFIG_FILE=$2; shift 2
  68. ;;
  69. -t|--sshtimeout)
  70. SSHTIMEOUT=$2; shift 2
  71. ;;
  72. -T|--fttimeout)
  73. SCPTIMEOUT=$2; shift 2
  74. ;;
  75. -L|--bwlimit)
  76. BWLIMIT=$2; shift 2
  77. ;;
  78. --log)
  79. LOG_FILE=$2; shift 2
  80. ;;
  81. -n|--ignore)
  82. IGNRFLAG="ignr"; shift
  83. ;;
  84. --)
  85. shift
  86. ;;
  87. *)
  88. echo -e "\033[31mERROR: unknown argument! \033[0m\n" && show_usage && exit 1
  89. ;;
  90. esac
  91. done
  92. ################ main #######################
  93. BEGINDATETIME=`date "+%F %T"`
  94. [ ! -f $IPLIST ] && echo -e "\033[31mERROR: iplist \"$IPLIST\" not exists, please check! \033[0m\n" && exit 1
  95. [ ! -f $CONFIG_FILE ] && echo -e "\033[31mERROR: config \"$CONFIG_FILE\" not exists, please check! \033[0m\n" && exit 1
  96. IP_count=$(egrep -v '^#|^$' $IPLIST|wc -l)
  97. IP_init=1
  98. while [[ $IP_init -le $IP_count ]]
  99. do
  100. egrep -v '^#|^$' $IPLIST | sed -n "$IP_init,$(expr $IP_init + 50)p" > $IPLIST.tmp
  101. IPSEQ=0
  102. while read IP PORT USER PASSWD PASSWD_2ND PASSWD_3RD PASSWD_4TH OTHERS
  103. # while read Line
  104. do
  105. [ -z "`echo $IP | grep -E '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}|CNS'`" ] && continue
  106. if [ "`python ./ckssh.py $IP $PORT`" == 'no' ];then
  107. [ ! -e ipnologin.txt ] && > ipnologin.txt
  108. [ -z "`grep $IP ipnologin.txt | grep $(date +%F)`" ] && echo "`date +%F_%H%M` $IP" >> ipnologin.txt
  109. continue
  110. fi
  111. #[ -e "~/.ssh/known_hosts" ] && grep $IP ~/.ssh/known_hosts | sed -i "/$IP/d" ~/.ssh/known_hosts
  112. let IPSEQ=$IPSEQ+1
  113. if [ $IGNRFLAG == "ignr" ]; then
  114. ignore_init
  115. ignored_flag=0
  116. i=0
  117. while [ $i -lt $array_ignore_pwd_length ]
  118. do
  119. [ ${PASSWD}x == ${array_ignore_pwd[$i]}x ] && ignored_flag=1 && break
  120. let i=$i+1
  121. done
  122. [ $ignored_flag -eq 1 ] && continue
  123. j=0
  124. while [ $j -lt $array_ignore_ip_length ]
  125. do
  126. [ ${IP}x == ${array_ignore_ip[$j]}x ] && ignored_flag=1 && break
  127. let j=$j+1
  128. done
  129. [ $ignored_flag -eq 1 ] && continue
  130. fi
  131. PASSWD_USE=$PASSWD
  132. IPcode=$(echo "ibase=16;$(echo "$IP" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
  133. Portcode=$(echo "ibase=16;$(echo "$PORT" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
  134. #USER=$USER
  135. PWcode=$(echo "ibase=16;$(echo "$PASSWD_USE" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
  136. Othercode=$(echo "ibase=16;$(echo "$OTHERS" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
  137. #echo $IPcode $Portcode $USER $PWcode $CONFIG_FILE $SSHTIMEOUT $SCPTIMEOUT $BWLIMIT $Othercode
  138. ./thread.sh $IPcode $Portcode $USER $PWcode $CONFIG_FILE $SSHTIMEOUT $SCPTIMEOUT $BWLIMIT $Othercode | tee logs/$IP.log &
  139. done < $IPLIST.tmp
  140. sleep 3
  141. IP_init=$(expr $IP_init + 50)
  142. done
  143. ENDDATETIME=`date "+%F %T"`
  144. echo "$BEGINDATETIME -- $ENDDATETIME"
  145. echo "$0 $* --excutes over!"
  146. exit 0