mabs.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 :; do
  54. [ -z "$1" ] && break;
  55. case "$1" in
  56. -h|--help)
  57. show_usage; exit 0
  58. ;;
  59. -v|-V|--version)
  60. show_version; exit 0
  61. ;;
  62. -l|--iplist)
  63. IPLIST=$2; shift 2
  64. ;;
  65. -c|--config)
  66. CONFIG_FILE=$2; shift 2
  67. ;;
  68. -t|--sshtimeout)
  69. SSHTIMEOUT=$2; shift 2
  70. ;;
  71. -T|--fttimeout)
  72. SCPTIMEOUT=$2; shift 2
  73. ;;
  74. -L|--bwlimit)
  75. BWLIMIT=$2; shift 2
  76. ;;
  77. --log)
  78. LOG_FILE=$2; shift 2
  79. ;;
  80. -n|--ignore)
  81. IGNRFLAG="ignr"; shift
  82. ;;
  83. --)
  84. shift
  85. ;;
  86. *)
  87. echo -e "\033[31mERROR: unknown argument! \033[0m\n" && show_usage && exit 1
  88. ;;
  89. esac
  90. done
  91. ################ main #######################
  92. BEGINDATETIME=`date "+%F %T"`
  93. [ ! -f $IPLIST ] && echo -e "\033[31mERROR: iplist \"$IPLIST\" not exists, please check! \033[0m\n" && exit 1
  94. [ ! -f $CONFIG_FILE ] && echo -e "\033[31mERROR: config \"$CONFIG_FILE\" not exists, please check! \033[0m\n" && exit 1
  95. IP_count=$(egrep -v '^#|^$' $IPLIST|wc -l)
  96. IP_init=1
  97. while [[ $IP_init -le $IP_count ]]
  98. do
  99. egrep -v '^#|^$' $IPLIST | sed -n "$IP_init,$(expr $IP_init + 50)p" > $IPLIST.tmp
  100. IPSEQ=0
  101. while read IP PORT USER PASSWD PASSWD_2ND PASSWD_3RD PASSWD_4TH OTHERS
  102. # while read Line
  103. do
  104. [ -z "`echo $IP | grep -E '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}|CNS'`" ] && continue
  105. if [ "`python ./ckssh.py $IP $PORT`" == 'no' ];then
  106. [ ! -e ipnologin.txt ] && > ipnologin.txt
  107. [ -z "`grep $IP ipnologin.txt | grep $(date +%F)`" ] && echo "`date +%F_%H%M` $IP" >> ipnologin.txt
  108. continue
  109. fi
  110. #[ -e "~/.ssh/known_hosts" ] && grep $IP ~/.ssh/known_hosts | sed -i "/$IP/d" ~/.ssh/known_hosts
  111. let IPSEQ=$IPSEQ+1
  112. if [ $IGNRFLAG == "ignr" ]; then
  113. ignore_init
  114. ignored_flag=0
  115. i=0
  116. while [ $i -lt $array_ignore_pwd_length ]
  117. do
  118. [ ${PASSWD}x == ${array_ignore_pwd[$i]}x ] && ignored_flag=1 && break
  119. let i=$i+1
  120. done
  121. [ $ignored_flag -eq 1 ] && continue
  122. j=0
  123. while [ $j -lt $array_ignore_ip_length ]
  124. do
  125. [ ${IP}x == ${array_ignore_ip[$j]}x ] && ignored_flag=1 && break
  126. let j=$j+1
  127. done
  128. [ $ignored_flag -eq 1 ] && continue
  129. fi
  130. PASSWD_USE=$PASSWD
  131. IPcode=$(echo "ibase=16;$(echo "$IP" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
  132. Portcode=$(echo "ibase=16;$(echo "$PORT" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
  133. #USER=$USER
  134. PWcode=$(echo "ibase=16;$(echo "$PASSWD_USE" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
  135. Othercode=$(echo "ibase=16;$(echo "$OTHERS" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
  136. #echo $IPcode $Portcode $USER $PWcode $CONFIG_FILE $SSHTIMEOUT $SCPTIMEOUT $BWLIMIT $Othercode
  137. ./thread.sh $IPcode $Portcode $USER $PWcode $CONFIG_FILE $SSHTIMEOUT $SCPTIMEOUT $BWLIMIT $Othercode | tee logs/$IP.log &
  138. done < $IPLIST.tmp
  139. sleep 3
  140. IP_init=$(expr $IP_init + 50)
  141. done
  142. ENDDATETIME=`date "+%F %T"`
  143. echo "$BEGINDATETIME -- $ENDDATETIME"
  144. echo "$0 $* --excutes over!"
  145. exit 0