码迷,mamicode.com
首页 > 编程语言 > 详细

Python Ethical Hacking - NETWORK_SCANNER(2)

时间:2019-08-17 01:02:33      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:address   ble   rbo   http   timeout   pre   argparse   argument   ict   

DICTIONARIES

  • Similar to lists but use key instead of an index.

LISTS

  • List of values/elements, all can be stored in one variable.

Improving the Program Using a List of Dictionaries:

#!/usr/bin/env python

import scapy.all as scapy

def scan(ip):
    arp_request = scapy.ARP(pdst=ip)
    broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
    arp_request_broadcast = broadcast/arp_request
    answered_list = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]

    clients_list = []
    for element in answered_list:
        clients_dict = {"ip": element[1].psrc, "mac": element[1].hwsrc}
        clients_list.append(clients_dict)
    return clients_list

def print_result(results_list):
    print("IP\t\t\tMAC Address\n------------------------------------------")
    for client in results_list:
        print(client["ip"] + "\t\t" + client["mac"])
        
scan_result = scan("10.0.0.1/24")
print_result(scan_result)

Result:

技术图片

 

Complete the Python code:

#!/usr/bin/env python

import scapy.all as scapy
import argparse

def get_arguments():
    parser = argparse.ArgumentParser()
    parser.add_argument("-t", "--target", dest="target", help="Target IP / IP range.")
    options = parser.parse_args()
    return options

def scan(ip):
    arp_request = scapy.ARP(pdst=ip)
    broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
    arp_request_broadcast = broadcast/arp_request
    answered_list = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]

    clients_list = []
    for element in answered_list:
        clients_dict = {"ip": element[1].psrc, "mac": element[1].hwsrc}
        clients_list.append(clients_dict)
    return clients_list

def print_result(results_list):
    print("IP\t\t\tMAC Address\n------------------------------------------")
    for client in results_list:
        print(client["ip"] + "\t\t" + client["mac"])

options = get_arguments()
scan_result = scan(options.target)
print_result(scan_result)

 

技术图片

 

Python Ethical Hacking - NETWORK_SCANNER(2)

标签:address   ble   rbo   http   timeout   pre   argparse   argument   ict   

原文地址:https://www.cnblogs.com/keepmoving1113/p/11366960.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!