Check for running DHCP daemon?

Chris Angelico rosuav at gmail.com
Thu Jan 22 00:30:22 CET 2015


On Thu, Jan 22, 2015 at 10:06 AM, Jason Bailey <jbailey at emerytelcom.com> wrote:
> So I've got this python 3 script that needs to know if there is a running
> DHCP daemon (ISC DHCP server) on the local system. Is there a clean way to
> do this that (1) doesn't require me to do syscalls to local utilities (like
> ps, top, etc), and (2) doesn't require any custom modules (stock only)?

Not sure why you have these restrictions; normally I'd look at an
OS-provided status function (eg "/etc/init.d/isc-dhcp-server status",
which on my Debian system is implemented by looking for a PID file and
confirming with ps). But since DHCP uses port 67, you might be able to
use that; I don't know of a way, within your restrictions, to find out
if someone's bound to port 67, but you could send a DHCPDISCOVER
message to 127:0.0.1:67 and see if you get back an offer. That may not
be the best technique, but it could be done with just Python's
standard library. (Alternatively, if you're certain the DHCP server is
configured appropriately, you could send a DHCPREQUEST message with an
inappropriate IP and hope for a rejection.)

ChrisA



More information about the Python-list mailing list