主動信息收集--二層發現(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文件

總結:腳本大同小異~,記錄一下

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章