源码如下:

 rom scapy.all import *
import threading
import argparse
import logging
import re logging.getLogger('scapy.runtime').setLevel(logging.ERROR) def parse_ip(targets):
'''
解析192.168.1.1-254形式的IP段,分解成IP列表
'''
_split = targets.split('-')
first_ip = _split[0]
ip_split = first_ip.split('.')
ipdot4 = range(int(ip_split[3]),int(_split[1])+1)
ipaddrs = [ip_split[0]+'.'+ip_split[1]+'.'+ip_split[2]+'.'+str(p) for p in ipdot4]
return ipaddrs def arp_scan(target_ip):
'''
通过scapy的sr1函数进行ARP扫描
'''
try:
ans = sr1(ARP(pdst=target_ip),timeout=1,verbose=False)
if ans:
return ans
except Exception:
print '[-]发包错误'
exit(1) def parse_arp(target_ip):
'''
解析收到的ARP reply包,采集IP及其对应的MAC
'''
ans = arp_scan(target_ip)
if ans:
if ans.haslayer('ARP') and ans.fields['op'] == 2:
print '[+] IP:%s => MAC:%s' % (ans.fields['psrc'],ans.fields['hwsrc']) if __name__ == '__main__':
usage = 'python %(prog)s -t [targets]'
parser = argparse.ArgumentParser(usage=usage,epilog='以上做为说明,祝好运!',description='说明:指定IP或IP段进行ARP扫描.',version='V1.0')
parser.add_argument('-t',action='store',dest='targets',help='targets为IP或IP段,如192.168.1.x或192.168.1.1-254') args = parser.parse_args()
if args.targets == None:
parser.print_help()
elif (not re.match(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$',args.targets)) and \
(not re.match(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}-\d{1,3}$',args.targets)):
parser.print_help()
else:
targets = args.targets if re.match(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$',targets):
ip = targets
parse_arp(ip)
elif re.match(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}-\d{1,3}$',targets):
ips = parse_ip(targets)
for ip in ips:
t = threading.Thread(target=parse_arp,args=(ip,))
t.start()

运行结果如下:

 python exp2.py -t 192.168.1.1-254
[+] IP:192.168.1.1 => MAC:14:75:90:XX:XX:XX
[+] IP:192.168.1.111 => MAC:c6:36:55:XX:XX:XX
[+] IP:192.168.1.100 => MAC:68:3e:34:XX:XX:XX
[+] IP:192.168.1.112 => MAC:84:38:38:XX:XX:XX
[+] IP:192.168.1.114 => MAC:6c:8d:c1:XX:XX:XX
[+] IP:192.168.1.103 => MAC:84:38:38:XX:XX:XX
[+] IP:192.168.1.102 => MAC:58:1f:28:XX:XX:XX

Python编写的ARP扫描工具的更多相关文章

  1. 用Python编写博客导出工具

    用Python编写博客导出工具 罗朝辉 (http://kesalin.github.io/) CC 许可,转载请注明出处   写在前面的话 我在 github 上用 octopress 搭建了个人博 ...

  2. ARP扫描工具arp-scan

    ARP扫描工具arp-scan   arp-scan是Kali Linux自带的一款ARP扫描工具.该工具可以进行单一目标扫描,也可以进行批量扫描.批量扫描的时候,用户可以通过CIDR.地址范围或者列 ...

  3. python之web路径扫描工具

    # coding: UTF-8 import sys, os, time, httplibimport relist_http=[]  #http数组 def open_httptxt():  #打开 ...

  4. Python打造一个目录扫描工具

    目标:用Python3写一款小型的web目录扫描工具 功能:1.扫描指定站点 2.指定网站脚本类型来扫描 3.可控线程 4.可保存扫描结果 首先定义一个命令参数的函数 def parse_option ...

  5. 目不识丁的我使用Python编写汉字注音小工具

    一万点暴击伤害 人懒起来太可怕了,放了个十一充分激发了我的惰性.然后公众号就这么停了半个月,好惭愧- 新学期儿子的幼儿园上线了APP,每天作业通过app布置后,家长需要陪着孩子学习,并上传视频才算完成 ...

  6. 目录扫描工具 dirsearch 使用详解

    介绍 dirsearch 是一个python开发的目录扫描工具.和我们平时使用的dirb.御剑之类的工具一样,就是为了扫描网站的敏感文件和目录从而找到突破口. 特点 多线程 可保持连接 支持多种后缀( ...

  7. Python编写类似nmap的扫描工具

    文主要是利用scapy包编写了一个简易扫描工具,支持ARP.ICMP.TCP.UDP发现扫描,支持TCP SYN.UDP端口扫描,如下: usage: python scan.py <-p pi ...

  8. 用python编写的定向arp欺骗工具

    刚学习了scapy模块的一些用法,非常强大,为了练手,利用此模块编写了一个arp欺骗工具,其核心是构造arp欺骗包.加了一个-a参数用于进行全网欺骗,先暂不实现.代码如下: #--*--coding= ...

  9. 老李分享:使用 Python 的 Socket 模块开发 UDP 扫描工具

    老李分享:使用 Python 的 Socket 模块开发 UDP 扫描工具 poptest是业内唯一的测试开发工程师培训机构,测试开发工程师主要是为测试服务开发测试工具,在工作中要求你做网络级别的安全 ...

随机推荐

  1. NBOJv2——Problem 1037: Wormhole(map邻接表+优先队列SPFA)

    Problem 1037: Wormhole Time Limits:  5000 MS   Memory Limits:  200000 KB 64-bit interger IO format: ...

  2. UVA11367 Full Tank? 【分层图最短路】

    题目 After going through the receipts from your car trip through Europe this summer, you realised that ...

  3. 刷题总结——二逼平衡树(bzoj3224线段树套splay)

    题目: Description 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:1.查询k在区间内的排名2.查询区间内排名为k的值3.修改某一位值上的数值4.查询k在 ...

  4. 洛谷 [P2480] 古代猪文

    卢卡斯定理 注意特判底数和模数相等的情况 http://www.cnblogs.com/poorpool/p/8532809.html #include <iostream> #inclu ...

  5. 转 php simple test

    转自 后期移至 以下为汪大哥写的 yunlian服务监控 如何写监控代码 首先在tests目录下新建一个文件xxx.php.其中xxx为你的服务名. class XxxTestCase extends ...

  6. 简单说明PHP的垃圾收集机制是怎样的?【转】

    原文链接: https://www.cnblogs.com/gengyi/p/6372020.html?utm_source=itdadao&utm_medium=referral.   对变 ...

  7. iOS上实现圆角图片

    UIImageView自带 //圆角设置 imageView.layer.cornerRadius = ;(值越大,角就越圆) imageView.layer.masksToBounds = YES; ...

  8. [react-router] 平时积累

    path通配符: <Route path="/hello/:name"> // 匹配 /hello/michael // 匹配 /hello/ryan <Rout ...

  9. AC日记——线段树练习4 codevs 4919

    4919 线段树练习4  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Description 给你N个数,有两种操作 ...

  10. 51nod 1092 回文字符串【LCS】

    1092 回文字符串 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 收藏 关注 回文串是指aba.abba.cccbccc.aaaa这种左右对称的字符串.每个字符 ...