CREATING DHCP DISCOVER PACKET

Homer Wilson Smith homer at lightlink.com
Wed Mar 9 03:43:20 UTC 2011


    Dear Gentle Folk,

    I have a short script included below that sends a DHCP discover packet 
FROM a linux dhcp server that serves many students on eth1.

    The students are prone to plugging in their linksys routers backwards, 
thus handing out DHCP IP's to each other in competition with the proper 
linux server IP's that they are supposed to get.  Yes I know vlaning the 
mess would stop this.

    The program I have sends a DHCP DISCOVER, so that I can see
the reponses from the errant student router.  Once I have his
MAC address from the tcpdump of his response, I can find his port
on the switch system and lock him out.

    The problem is that some student routers only respond to DISCOVER
requests with 0.0.0.0 as the from IP.  The perl script below sends
the packet with the IP of the sending linux server, and is thus
ignored by some student routers, making it harder to track them down.

    Is there an easy change to the script below to fix this problem?

    Thanks in advance, and thanks for all the great work on DHCP.

    Homer
#!/usr/bin/perl
    # Simple DHCP client - sending a broadcasted DHCP Discover request

    use IO::Socket::INET;
    use Net::DHCP::Packet;
    use Net::DHCP::Constants;

    # creat DHCP Packet
    $discover = Net::DHCP::Packet->new(
                          xid => int(rand(0x12345678)), # random xid
                          Flags => 0x8000,              # ask for broadcast
                          DHO_DHCP_MESSAGE_TYPE() => DHCPDISCOVER()
                          );

    # send packet
    $handle = IO::Socket::INET->new(Proto => 'udp',
                                    Broadcast => 1,
                                    PeerPort  => '67',
                                    LocalPort => '68',
                                    LocalAddr => '10.19.0.1',
                                    PeerAddr  => '255.255.255.255')
                  or die "socket: $@";     # yes, it uses $@ here
    $handle->send($discover->serialize())
                  or die "Error sending broadcast inform:$!\n";


------------------------------------------------------------------------
Homer Wilson Smith     The Paths of Lovers    Art Matrix - Lightlink
(607) 277-0959 KC2ITF        Cross            Internet Access, Ithaca NY
homer at lightlink.com    In the Line of Duty    http://www.lightlink.com



More information about the dhcp-users mailing list