Results 1 to 4 of 4

Thread: Run script after dhcpd assigned ip to client

  1. #1
    Join Date
    Aug 2009
    Beans
    5
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Smile Run script after dhcpd assigned ip to client

    Hello,

    Does anyone know if there is a way to get dhcpd to run a script on the server side after a client has requested an ip? I would like the script to run a check on the mac address and then depending on what the result is either re-direct the users browser to a page on the server or allow access to internet. the closest thing i can find is along the lines of running tail on the messages log for events. Unfortunately the script will lock up while it waits for tail. Is there any "Event" i can use to invoke the startup of a script on the server side?
    Last edited by oddwareso; November 17th, 2009 at 05:33 AM. Reason: spelling

  2. #2
    Join Date
    Dec 2008
    Beans
    Hidden!
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Run script after dhcpd assigned ip to client

    Quote Originally Posted by oddwareso View Post
    Hello,

    Does anyone know if there is a way to get dhcpd to run a script on the server side after a client has requested an ip?
    My guess is that dhcpd will not trigger a script directly. The request, offer, etc. routine for an IP address is unto itself.
    I would like the script to run a check on the mac address and then depending on what the result is either re-direct the users browser to a page on the server or allow access to internet.
    This is probably best handled with a proxy server such as squid.
    the closest thing i can find is along the lines of running tail on the messages log for events. Unfortunately the script will lock up while it waits for tail. Is there any "Event" i can use to invoke the startup of a script on the server side?
    Squid will limit specific hosts access to the internet. But you have to configure each client to use the proxy. The event is the clients HTTP request.

  3. #3
    Join Date
    Oct 2006
    Location
    Belfast
    Beans
    3
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Run script after dhcpd assigned ip to client

    There is a config entry you can put in your dhcpd.conf file that will allow you to run stuff when events occur. In dhcpd 3.1pre there was the ability to exec programs but I'm not sure if that is still around, you'd have to have a look at the source.

  4. #4
    Join Date
    Oct 2006
    Location
    Belfast
    Beans
    3
    Distro
    Ubuntu 10.04 Lucid Lynx

    Post Re: Run script after dhcpd assigned ip to client

    Just went away and looked it up, you'll want something like this in your dhcpd.conf file...

    Code:
    on commit {
            set ClientIP = binary-to-ascii(10, 8, ".", leased-address);
            set ClientMac = binary-to-ascii(16, 8, ":", substring(hardware, 1, 6));
            log(concat("Commit: IP: ", ClientIP, " Mac: ", ClientMac));
            execute("/usr/sbin/my_script_here", "commit", ClientIP, ClientMac);
    }
    Please note that the script you call is called synchronously, this means if your script takes time to run it will stop your dhcpd server from responding. If your script takes a while to run make sure you fork and get the parent to exit straight away.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •