主动信息收集--二层发现(shell脚本)

二层发现

原理:使用ARP协议,在网段内进行广播,查看是否有回包,如果有,证明该主机存活;
优点:扫描速度快、可靠;
缺点:不可路由,只能发现同一网段内的主机;

环境

kali 2.0

利用arping命令结合脚本实现主机发现

脚本一(网络接口)

#!/bin/bash
#Author:Tao

if [ $# -ne 1 ];then
    echo "Usage ./arp.sh [interface]"
    exit
fi
intface=$1
ipd=$(ifconfig eth0 | grep 'netmask' | cut -d ' ' -f 10 | cut -d '.' -f 1-3)
for num in $(seq 1 255);do
    ip=$ipd.$num
    arping -c 1 $ip | grep bytes | cut -d ' ' -f 5 | cut -d '(' -f 2 | cut -d ')' -f 1
done

脚本一效果图:
《主动信息收集--二层发现(shell脚本)》

脚本二(网络接口,无参数)

#!/bin/bash
#Author:Tao

interface=$(ifconfig | head -1 | awk -F ":" '{print $1}')
ip=$(ifconfig $interface | grep "netmask" | awk '{print $2}'| cut -d '.' -f 1-3)
for i in `seq 1 254`;do
    arping -c 1 $ip.$i | grep from | cut -d " " -f 5 | cut -d "(" -f 2 | cut -d ")" -f 1
done > alive.txt

注:以上脚本结果回输入到alive.txt文件
脚本二效果图:
《主动信息收集--二层发现(shell脚本)》
《主动信息收集--二层发现(shell脚本)》

脚本三(文件传入IP)

#!/bin/bash
#Author:Tao

file=$1
for i in $(cat $1);do
    arping -c 1 $i | grep from | cut -d " " -f 5 | cut -d "(" -f 2 | cut -d ")" -f 1
done > $1-alive.txt

《主动信息收集--二层发现(shell脚本)》
《主动信息收集--二层发现(shell脚本)》
注:以上脚本结果回输入到你传的文件名+alive.txt文件

总结:脚本大同小异~,记录一下

    原文作者:YWBOY
    原文地址: https://blog.51cto.com/14113984/2443992
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞