1.掃描同一網絡內IP使用狀況bash
- #!/bin/bash
- #-------------------------------
- #Version 0.1
- #Filename: ipscan.sh
- #Date: 2011.03.22
- #Email: liyaoyi@163.com
- #-------------------------------
- #
- #定義變量
- NETWORK=$(ifconfig eth0 | grep "inet addr" | awk '{print $2}'|awk -F: '{print $2}' \
- | awk -F"." '{print $1"."$2"."$3}')
- IPTEMP=$(mktemp)
- IPUP="/tmp/ipup.txt"
- IPDOWN="/tmp/ipdown.txt"
- if [ ! -f "$IPUP" -a ! -f "$IPDOWN" ]; then
- touch $IPUP $IPDOWN
- fi
- #掃描網絡並分類輸出IP
- echo "正在執行掃描,請稍候..."
- echo ""
- for ip in `seq 1 254`
- do
- arping -c 1 "$NETWORK".$ip > $IPTEMP
- if [ $? -eq 0 ]; then
- cat $IPTEMP | grep "reply" | awk '{print $4,$5}' >> $IPUP
- else
- cat $IPTEMP | head -n 1 | awk '{print $2}' >> $IPDOWN
- fi
- done
- #將結果輸出並清除臨時文件
- clear
- echo "正在使用的IP及MAC:"
- echo ""
- cat $IPUP
- echo ""
- echo "未使用的IP:"
- echo ""
- cat $IPDOWN
- echo ""
- rm -f $IPTEMP $IPUP $IPDOWN
- #!/bin/bash
- #Date: 20120322
- TMP=`mktemp`
- DEFINE=20
- log=/var/log/black.log
- cat /var/log/secure | awk '/Failed/{print $(NF-3)}' | sort | uniq -c | awk '{print $2"="$1}' > $TMP
- for i in `cat $TMP`
- do
- IP=`echo $i | awk -F"=" '{print $1}'`
- NUM=`echo $i | awk -F"=" '{print $2}'`
- if [ $NUM -gt $DEFINE ]; then
- grep $IP /etc/hosts.deny > /dev/null
- if [ $? -gt 0 ];then
- echo "sshd:$IP">>/etc/hosts.deny
- fi
- fi
- done
- rm -rf $TMP