LoginSignup
0
1

簡易DHCPサーバ確認

Last updated at Posted at 2024-04-30

send DHCP Discover

send.py
from scapy.all import Ether, IP, UDP, BOOTP, DHCP, sendp, RandMAC

for _ in range(5):
    mac = str(RandMAC())
    chaddr = "".join([chr(int(x, 16)) for x in mac.split(":")])

    discover = (
        Ether(dst="ff:ff:ff:ff:ff:ff", src=mac, type=0x0800)
        / IP(src="0.0.0.0", dst="255.255.255.255")
        / UDP(dport=67, sport=68)
        / BOOTP(op=1, chaddr=chaddr)
        / DHCP(options=[("message-type", "discover"), ("end")])
    )
    sendp(discover, verbose=0)

recieve DHCP Offer

recv.py
from scapy.all import sniff


def on_dhcp_offer(packet):
    print(packet.summary())


sniff(prn=on_dhcp_offer, filter="udp src port 67", store=0)

filterはBPF syntax。詳細こちら

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1