1
0

mabs.sh 4.5 KB

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