Created
March 2, 2012 16:50
-
-
Save robertondc/1959609 to your computer and use it in GitHub Desktop.
dhcp_server.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pydhcplib.dhcp_packet import * | |
from pydhcplib.dhcp_network import * | |
import threadpool | |
netopt = { "client_listen_port": "68", | |
"iface": "eth0", | |
"server_listen_port": "67", | |
"listen_address": "0.0.0.0" | |
} | |
class Server(DhcpServer): | |
def __init__(self, options): | |
self.pool = threadpool.ThreadPool(15) | |
DhcpServer.__init__(self, | |
options["iface"], | |
options["listen_address"], | |
options["client_listen_port"], | |
options["server_listen_port"] | |
) | |
def async_reply(self, req, rsp): | |
task = threadpool.WorkRequest(self.SendDhcpPacket, (req, rsp), ) | |
self.pool.putRequest(task) | |
def HandleDhcpAll(self, req): | |
pass | |
def HandlDhcpDiscover(self, req): | |
rsp = DhcpPacket() | |
rsp.CreateDhcpOfferPacketFrom(req) | |
rsp.SetOption("yiaddr", [172,19,81,3]) | |
rsp.SetOption("subnet_mask", [255,255,255,0]) | |
rsp.SetOption("router", [172,19,81,1]) | |
rsp.SetOption("ip_address_lease_time", [0xFF,0xFF,0xFF,0xFF]) | |
self.async_reply(req, rsp) | |
def HandleDhcpRequest(self, req): | |
rsp = DhcpPacket() | |
rsp.CreateDhcpAckPacketFrom(req) | |
rsp.SetOption("yiaddr", [172,19,81,3]) | |
rsp.SetOption("subnet_mask", [255,255,255,0]) | |
rsp.SetOption("router", [172,19,81,1]) | |
rsp.SetOption("ip_address_lease_time", [0xFF,0xFF,0xFF,0xFF]) | |
self.async_reply(req, rsp) | |
def HandleDhcpDecline(self, req): | |
pass | |
def HandleDhcpRelease(self, req): | |
pass | |
def HandleDhcpInform(self, req): | |
pass | |
server = Server(netopt) | |
while True : | |
server.GetNextDhcpPacket() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment