网卡厂商自动识别工具(Python版, 附源代码)

网卡厂商自动识别工具(Python版, 附源代码)

黑客软件hacker2019-06-18 10:24:3110191A+A-

"看过这篇 ,感觉很好用,因此写了1个python 版的,适用Linux 和windows 服务平台应用,针对Linux (arp -n ) 和windows (arp -a)导出来的arp表,开展分析并輸出結果。 

怎么使用

 网卡厂商自动识别工具(Python版, 附源代码) 第1张

–oui-file 指的是 oui.txt的相对路径,程序流程默认值为当前目录下的oui.txt , 即:./oui.txt

–arp-tab-file 指的是 导出来的arp表的相对路径

1、最先你可以导出来系统软件上的arp 表

 windows > arp -a > arp.txt Linux # arp -n >arp.txt 

2、 随后实行网口生产商分析专用工具(这儿暂为Mac.py)

3、分析結果储存在当前目录下的result.txt 中

检测实际效果给出:

Linux:

 

Windows:

 

源代码:

#!/usr/bin/env python # -*- coding:utf8 -*- """"""

Coded By bgusko63190

"""""" import Re import sys import codecs import argparse def parse_oui(oui_path): """"""

     加载并分析oui.txt,转化成'生产商标志':'生产商名字' 词典

    """""" oui_dict = dict() with codecs.open(oui_path, 'r', encoding='utf8') as fd: For line In fd: if '(hex)' In line:

                _line = line.split('(hex)')

                flag = _line[0].strip()

                manufacturers = _line[1].strip()

                oui_dict[flag] = manufacturers return oui_dict def parse_arp_tab(arp_tab_path, oui_path): """"""

    :param arp_tab_path: arp -n 生生結果储存文档相对路径(适用windows Ar -a 和Linux的arp -n 結果文件格式)

    :param oui_path: oui.txt的相对路径

    :return:

    """""" parse_result = []

    oui_dict = parse_oui(oui_path) # 适用  03:43:5a:37:9f:57 , 03-43-5a-37-9f-57,00.42.5a.38.9f.56 3种文件格式的Mac详细地址 Mac_pattern = Re.compile( '([0-9a-fA-F]{1,2}[-]){5}([0-9a-fA-F]{1,2})|([0-9a-fA-F]{1,2}[:]){5}([0-9a-fA-F]{1,2})|([0-9a-fA-F]{1,2}[.]){5}([0-9a-fA-F]{1,2})',

        Re.VERBOSE | Re.IGNORECASE)

    result_lines = [] with codecs.open(arp_tab_path, 'r', encoding='utf8') as fd: For line In fd:

            _line = None if u'种类' In line:

                _line = line.strip() + '\t\t' + u'生产商' elif 'Type' In line or 'Iface' In line:

                _line = line.strip() + '\t\t' + 'manufacturers' else: try: if u'态' In line or 'dynamic' In line or 'static' In line or 'ether' In line: # _line = line.strip() + '\t\t' + oui_dict[Mac_pattern.search(line).group().rsplit('-', 3)[0].upper()] manu = Re.split('[-:.]', Mac_pattern.search(line).group(), 3)


点击这里复制本文地址 以上内容由黑资讯整理呈现,请务必在转载分享时注明本文地址!如对内容有疑问,请联系我们,谢谢!
  • 1条评论
  • 惑心近箐2022-06-08 14:56:36
  • ]{1,2})',        Re.VERBOSE | Re.IGNORECASE)    result_lines = [] with codecs.open

支持Ctrl+Enter提交

黑资讯 © All Rights Reserved.  
Copyright Copyright 2015-2020 黑资讯
滇ICP备19002590号-1
Powered by 黑客资讯 Themes by 如有不合适之处联系我们
网站地图| 发展历程| 留言建议| 网站管理