Git Product home page Git Product logo

dhcp-php's Introduction

dhcp

DHCP implementation in PHP

Build Status

src/DHCP/ contains an implementation of DHCP protocol in PHP. It can be used to translate any DHCP packet from the network into PHP objects and vice versa.

src/DHCPServer/ is a simple DHCP Server using the DHCP implementation, using PostgreSQL as a backend for storing lease information. It also supports assigning static ip addresses to clients and was tested with default DHCP Clients on Windows 7, MacOS Sierra and Red Hat Linux 7 (dhclient).

Why?

Simply to show it can be done. This code is not intended for production use, but as a learning exercise. It may be an easy way for PHP developers to learn more about DHCP protocol.

For more details and to see the code in action, check out our blog post: mysteriouscode.io/blog/dhcp-implementation-in-php/

Running DHCPServer

To start the server, run php src/DHCPServer/server.php serve x.x.x.x/y password_to_postgresql Replace x.x.x.x/y with an IP and mask for the server (for example, 10.0.0.0/25) and password_to_postgres with a password to PostgreSQL.

To change database IP address, database name and user, go to src/DHCPServer/Postgresql.php line 12.

PostgreSQL tables for DHCPServer

Two PostreSQL tables are required and have to be created before the server can run:

dhcp_leases holds information about leases given to clients and their expiry dates:

CREATE TABLE dhcp_leases
(
  id serial NOT NULL,
  ip inet,
  mac macaddr,
  reason text,
  assigned_on timestamp without time zone,
  expires_on timestamp without time zone,
  CONSTRAINT dhcp_leases_id_pk PRIMARY KEY (id)
)
WITH (
  OIDS=FALSE
);

dhcp_static holds a list of static IP addresses for each client based on its MAC address:

CREATE TABLE dhcp_static
(
  id serial NOT NULL,
  ip inet,
  dns inet[],
  lease_time integer,
  mac macaddr,
  router inet,
  CONSTRAINT dhcp_static_id_pk PRIMARY KEY (id),
  CONSTRAINT dhcp_static_ip_pk UNIQUE (ip)
)
WITH (
  OIDS=FALSE
);

dhcp-php's People

Contributors

eugenganshorn avatar pbudzon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.