Python Ethical Hacking - NETWORK_SCANNER(1)

本文介绍了一个Python脚本,使用Scapy模块来发现局域网内的所有设备。脚本发送ARP请求到广播MAC地址,询问目标IP,设置目的地MAC为广播MAC,接收并解析响应,最后打印出每个设备的IP地址和MAC地址。

NETWORK_SCANNER

  • Discover all devices on the network.
  • Display their IP address.
  • Display their MAC address.

 

Write the Python code using the scapy.all module.

Refer to: https://scapy.readthedocs.io/en/latest/installation.html

#!/usr/bin/env python

import scapy.all as scapy

def scan(ip):
    scapy.arping(ip)

scan("10.0.0.1/24")

 

ALGORITHM

Goal -> Discover clients on the network.

Steps:

1. Create arp request directed to broadcast MAC asking for IP.

Two main parts:

-> Use ARP to ask who has target IP.

-> Set destination MAC to broadcast MAC.

2. Send packet and receive a response.

3. Parse the response.

4. Print result.

 

Use the scapy module in this program.

https://scapy.readthedocs.io/en/latest/usage.html

 

EX: Python Script to discover the clients on the network.

#!/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]

    print("IP\t\t\tMAC Address\n------------------------------------------")
    for element in answered_list:
        print(element[1].psrc + "\t\t" + element[1].hwsrc)

scan("10.0.0.1/24")

 

Execute the script and show the result.

 

转载于:https://www.cnblogs.com/keepmoving1113/p/11334464.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值