Python Raw Socket to Ethernet Interface (Windows)

后端 未结 5 738
滥情空心
滥情空心 2021-01-15 06:14

I\'m trying to create a DHCP Server and the first step is for me to send packets through my ethernet port. I\'m trying to send packets to my Ethernet interface and having an

5条回答
  •  误落风尘
    2021-01-15 06:24

    Approaching your question from another direction: why do you need to work with ethernet at all? DHCP is usually implemented via UDP.

    1. DHCP server always has some IP address (and a pool of addresses it can lease).
    2. If a client wants and IP (DHCP actually can do much more than just assign IPs but let's stop on this use case for now), it sends a broadcast DHCPREQUEST with source IP 0.0.0.0 and destination IP 255.255.255.255. The servers answer him via UDP broadcast as well, but with his own source IP.

    If you want to create an implementation of DHCP, starting with OSI Level 2 (ethernet) will just give you headache of maintaining Level 3 (IP) and 4 (UDP). I don't see any benefit in this.

    If you'd like to create a DHCP-like protocol based on ethernet be ready to work on the following issue: routers don't forward broadcast packets unless asked to do so. For instance, for Cisco routers it looks like this:

    router(config)# interface ethernet 0/0
    router(config-if)# ip helper-address 10.1.23.5
    router(config-if)# end
    router#
    

    Thus we configure router so it knows there's something helpful connected to ethernet 0/0 port with IP 10.1.23.5 that needs broadcasts (source).

提交回复
热议问题