千家信息网

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

发表于:2024-10-03 作者:千家信息网编辑
千家信息网最后更新 2024年10月03日,二层发现原理:使用ARP协议,在网段内进行广播,查看是否有回包,如果有,证明该主机存活;优点:扫描速度快、可靠;缺点:不可路由,只能发现同一网段内的主机;环境kali 2.0利用arping命令结合脚
千家信息网最后更新 2024年10月03日主动信息收集--二层发现(shell脚本)

二层发现

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

环境

kali 2.0

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

脚本一(网络接口)
#!/bin/bash#Author:Taoif [ $# -ne 1 ];then    echo "Usage ./arp.sh [interface]"    exitfiintface=$1ipd=$(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 1done

脚本一效果图:

脚本二(网络接口,无参数)
#!/bin/bash#Author:Taointerface=$(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 1done > alive.txt

注:以上脚本结果回输入到alive.txt文件
脚本二效果图:

脚本三(文件传入IP)
#!/bin/bash#Author:Taofile=$1for i in $(cat $1);do    arping -c 1 $i | grep from | cut -d " " -f 5 | cut -d "(" -f 2 | cut -d ")" -f 1done > $1-alive.txt



注:以上脚本结果回输入到你传的文件名+alive.txt文件

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

0