Git Product home page Git Product logo

python_dhcp_server's Introduction

Python DHCP Server

Download

This is a purely Python DHCP server that does not require any additional libraries or installs other that Python 3.

It was testet under Ubuntu 14 with Python and Windows 7. It does not use any operating system specific Python functions, so it should work when Python 3 works.

images/dhcpgui.png
dhcpgui lists MAC address, IP address and host name.

This DHCP server program will assign IP addresses ten seconds after it received packets from clients. So it can be used in networks that already have a dhcp server running.

This Python DHCP server

  • shows clients in the network
  • lists IP address, Mac address and host name
  • highlights recently refreshed/added clients
  • assigns IP addresses 10 seconds later than usual DHCP servers
  • remembers addresses in the hosts.csv file.
  • can be configured to serve all DHCP options using Python

Contributions welcome!

Windows

You can install this software by downloading the release named python_dhcp_server_standalone_X.Y.zip file. Unpack the zip file, you will find an executable .exe file inside.

Linux

Under Linux you can download the source code and install Python 3 and Tkinter for Python 3:

sudo apt-get install python3 python3-tk

There are different ways to start:

  1. You can use the python_dhcp_server.desktop and double-click it. If it does not open, please report it and try the next one.
  2. You can run the following command provided you are in the server directory.
    sudo python3 ./dhcpgui.pyw
    

Related Work

This program was created to find Raspberry Pis in the network.

Changelog

  • 0.9
    • Add icon to exe file and application
    • Add flatpak build information
  • 0.8
    • Make text field expandable
    • Show error message if DHCP port cannot be accessed
  • 0.7
    • Prevent duplicate assignment of IP addresses
    • Add sliders to the GUI
  • 0.6
    • Use a queue
    • Run in Linux
    • Add install description
    • Add ability to bind to a fixed IP address
  • 0.5
    • Fix issue with delay worker
  • 0.4
    • Fix issue with delay worker
    • Add license
  • 0.3
    • Also show old values
    • Random IP assignment when address space is full
  • 0.2
    • Add .exe file
    • Add width and height
  • 0.1
    • Mark new entries as yellow
    • Initial release

New Releases

When the source code is changed, create a new release.

  1. Log the changes: Edit the Changelog Section in
    • README.md
    • python_dhcp_server/flatpak/io.github.niccokunzmann.python_dhcp_server.xml
    git log # find changes
    git add README.md
    git commit -m"log changes"
    
  2. Create a new tag
    git tag 0.10
    git push origin 0.10
    
  3. Download the latest release.
    cd ~/Downloads
    wget -c 'https://github.com/niccokunzmann/python_dhcp_server/releases/download/0.9/python_dhcp_server_standalone_0.9.zip'
    
  4. Unzip it.
    rm -rf python_dhcp_server_standalone
    unzip python_dhcp_server_standalone_0.9.zip
    
  5. Replace the server directory.
    cd python_dhcp_server_standalone
    rm -r server
    cp -r ~/python_dhcp_server/server/ .
    rm -r server/__pycache__
    
  6. Zip the release.
    cd ..
    zip -9r python_dhcp_server_standalone_0.10.zip python_dhcp_server_standalone
    
  7. Upload the zip file to the pushed release.
  8. Head over to the Flathub metadata and create a new release.

python_dhcp_server's People

Contributors

greggzj avatar joshhazelhurst123 avatar mjmdavis avatar niccokunzmann avatar va3yao avatar vitormhenrique 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

python_dhcp_server's Issues

Reuse oldest ip addresses

If all 250 addresses were taken then there should not be a random selection but a selection that knows which entry was taken earliest and reassign that, removing the old entry from the database/having a look if the IP is free.

Threading/Queue Issue

I have been running into the following error messages while running the DHCP server. I don't understand multithreating enough to know how to resolve the issue. Has anyone seen this issue before? It seems to happen the longer I leave the server running or how many devices I boot up at once.

Traceback (most recent call last):
File "C:\Users\user\Desktop\Python\SSH Tool\IOS PnP\dhcp.py", line 529, in run
self.update(1)
File "C:\Users\user\Desktop\Python\SSH Tool\IOS PnP\dhcp.py", line 448, in update
self.received(packet)
File "C:\Users\user\Desktop\Python\SSH Tool\IOS PnP\dhcp.py", line 455, in received
if not self.transactions[packet.transaction_id].receive(packet):
File "C:\Users\user\Desktop\Python\SSH Tool\IOS PnP\dhcp.py", line 167, in receive
self.received_dhcp_request, (packet,), )
File "C:\Users\user\Desktop\Python\SSH Tool\IOS PnP\dhcp.py", line 139, in do_after
self.queue.put((time.time() + seconds, func, args, kw))
known ip: 192.168.0.79
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\queue.py", line 143, in put
self._put(item)
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\queue.py", line 227, in _put
heappush(self.queue, item)
TypeError: '<' not supported between instances of 'method' and 'method'

Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\user\Desktop\Python\SSH Tool\IOS PnP\dhcp.py", line 131, in _delay_response_thread
p = self.queue.get(timeout=1)
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\queue.py", line 174, in get
item = self._get()
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\queue.py", line 230, in _get
return heappop(self.queue)
TypeError: '<' not supported between instances of 'method' and 'method'

Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\user\Desktop\Python\SSH Tool\IOS PnP\dhcp.py", line 131, in _delay_response_thread
p = self.queue.get(timeout=2)
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\queue.py", line 174, in get
item = self._get()
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\queue.py", line 230, in _get
return heappop(self.queue)
TypeError: '<' not supported between instances of 'method' and 'method'

DHCP offers not being accepted

I have this set up on a pi to which a laptop is connected. The pi has a wifi and a wired interface, and the wired interface is connected directly to a laptop.

The pi is running the python DHCP server, whilst the laptop is requesting an IP

I can see the DHCP discovery messages coming in from the laptop to the Pi, and the Pi responds with an offer

However, the offer is never accepted - there seems to be no REQUEST message sent in response by the laptop - so the logs on the pi show a continuous stream of "DHCPDISCOVER", "DHCPOFFER"

discover:
Message Type: 1
client MAC address: 00:0E:C6:CA:BC:35
client IP address: 0.0.0.0
your IP address: 0.0.0.0
next server IP address: 0.0.0.0
client identifier: 01:00:0E:C6:CA:BC
dhcp message type: DHCPDISCOVER
host name: ben-laptop
maximum dhcp message size: 576
parameter request list: [1, 2, 6, 12, 15, 26, 28, 121, 3, 33, 40, 41, 42, 119, 249, 252, 17]

new ip: 192.168.2.6
add 00:0E:C6:CA:BC:35 192.168.2.6 ben-laptop
broadcasting:
Message Type: 2
client MAC address: 00:0E:C6:CA:BC:35
client IP address: 0.0.0.0
your IP address: 192.168.2.6
next server IP address: 0.0.0.0
broadcast address: 255.255.255.255
client identifier: 00:0E:C6:CA:BC:35
dhcp message type: DHCPOFFER
ip address lease time: 300
subnet mask: 255.255.255.0

Running wireshark on the laptop - the one issuing the DISCOVER messages, I can see the DHCPOFFER, but it seems a REQUEST response is never sent

Dynamic Host Configuration Protocol (Offer)
Message type: Boot Reply (2)
Hardware type: Ethernet (0x01)
Hardware address length: 6
Hops: 0
Transaction ID: 0x2eb6bcda
Seconds elapsed: 0
Bootp flags: 0x0001 (Unicast)
Client IP address: 0.0.0.0
Your (client) IP address: 192.168.2.6
Next server IP address: 0.0.0.0
Relay agent IP address: 0.0.0.0
Client MAC address: AsixElec_ca:bc:35 (00:0e:c6:ca:bc:35)
Client hardware address padding: 00000000000000000000
Server host name not given
Boot file name not given
Magic cookie: DHCP
Option: (1) Subnet Mask (255.255.255.0)
Length: 4
Subnet Mask: 255.255.255.0
Option: (28) Broadcast Address (192.168.2.255)
Length: 4
Broadcast Address: 192.168.2.255
Option: (51) IP Address Lease Time
Length: 4
IP Address Lease Time: (300s) 5 minutes
Option: (53) DHCP Message Type (Offer)
Length: 1
DHCP: Offer (2)
Option: (61) Client identifier
Length: 6
Type: 0
Client Identifier: \016���5
Option: (255) End
Option End: 255

add slider

you should be able to scroll up and down and know that that is possible

Create a new release

It would be nice to release a new version now that #19 has been fixed.
Here is my suggestion:

  • Add a changelog Section and #19 to it
  • Tag a new release
  • download the old release for Windows and update the files

DelayWorker keeping server alive

Hello,

I'm using your code to create a dhcp server but I'm running on a problem... It's been a while since you don't change this source code so I don't know if you are going to see this...

but the issue is the following, after creating the server object the DelayWorker is inited and generate a thread with a priority queue to run... but if I try to stop the server calling the .close command, setting the delayworker to closed is not releasing that thread, making the code "locked" on a state that it's only possible by sending and singint to the program (ctrl + c)

Do you have any idea how to fix this?

add configuration window

one should be able to replace the configuration using a menu.
Also, replace in the file if possible

remove old ip address entries

It may not be useful to hold entries very long. One should be able t always see the most important entries.

  • stick them to the top
  • sort by time
  • add find
  • allow removal of old entries

Client Identifier != mac

When the client_identifier gets parsed it seems to be one byte off.

The client identifier, which gets logged is 01:<mac_byte1>:<mac_byte2>:<mac_byte3>:<mac_byte4>:<mac_byte5>
This is the same value as in packet.named_options['client_identifier']. Also, while responding, the client identifier gets set from mac. This is not as defined in the standard

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.