KALI - 信息收集 - 二层扫描

0x0 目的

发现本网段内的存活主机

0x1 协议

ARP

0x2 工具

arping、nmap、netdiscover、scapy

0x3 py脚本

#! /usr/bin/python
import logging
import subprocess
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
from scapy.all import *

if len(sys.argv) != 2:
    print "####################"
    print "usage ./arp.py eth0 "
    print "####################"
    sys.exit()

interface = str(sys.argv[1]) #get arguments
subnet = subprocess.check_output("ifconfig "+interface+" | grep 'netmask'|awk '{print $2}'|cut -d \".\" -f 4 --complement",shell=True).strip()+"." #excute system command
for host in range(1,254):
    re_packet=sr1(ARP(pdst=subnet+str(host)),timeout=0.1,verbose=0)
    if re_packet != None:
        print subnet+str(host)

0x4 shell脚本

#! /bin/bash

if test $# -ne 1
then
echo "###############";
echo "#./arping eth0#"
echo "###############";
exit
fi

interface=$1
eth=`ifconfig $interface`
subnet=$(echo $eth | awk '{print $6}'|cut -d "." -f 4 --complement)"."
echo "subnet ==> $subnet0";
echo "Let's start scan!"
echo "================="
for host in `seq 1 254`
do
arping $subnet$host -c 1 | grep 'bytes from'|awk '{print $5}' | awk -F ')' '{print $1}'| cut -d '(' -f 2 >> /root/Desktop/shell/ip.txt
done
cat /root/Desktop/shell/ip.txt
echo "=====end====="
 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值