Skip to content

Commit

Permalink
Added service id to DHCP offer, added new asciinema and a try to pyth…
Browse files Browse the repository at this point in the history
…on perf
  • Loading branch information
wizche committed Feb 2, 2020
1 parent 9d8a806 commit 2d9735d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static async void StartServer(string interfaceIp, string targetIp)
Console.WriteLine($"Client will receive IP {targetIp}");
server.OnDataReceived += delegate (DHCPRequest dhcpRequest)
{
Request(dhcpRequest, IPAddress.Parse(targetIp));
Request(dhcpRequest, IPAddress.Parse(targetIp), interfaceIp);
};
server.BroadcastAddress = IPAddress.Broadcast;
server.SendDhcpAnswerNetworkInterface = intf;
Expand All @@ -84,13 +84,14 @@ public static async void StartServer(string interfaceIp, string targetIp)
await LoadingIndicator();
}

static void Request(DHCPRequest dhcpRequest, IPAddress targetIp)
static void Request(DHCPRequest dhcpRequest, IPAddress targetIp, string interfaceIp)
{
try
{
var type = dhcpRequest.GetMsgType();
var replyOptions = new DHCPReplyOptions();
replyOptions.SubnetMask = IPAddress.Parse("255.255.255.0");
replyOptions.ServerIdentifier = IPAddress.Parse(interfaceIp);

if (type == DHCPMsgType.DHCPDISCOVER)
{
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# dhcpshot

[![asciicast](https://asciinema.org/a/OyMydvQOw3imDCD9OLiyiPlUB.svg)](https://asciinema.org/a/OyMydvQOw3imDCD9OLiyiPlUB)
[![asciicast](https://asciinema.org/a/297377.svg)](https://asciinema.org/a/297377)

Use [DotNetProjects.DhcpServer](https://www.nuget.org/packages/DotNetProjects.DhcpServer/) library to quickly create a predefined DHCP Server answering with a fixed IP to request coming from the interface specified by the user. E.g.: you connect your RPI in DHCP mode directly to your laptop's ethernet interface.

Expand Down
9 changes: 9 additions & 0 deletions perfs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,13 @@ $ time for i in {1..30}; do bin/release/netcoreapp3.0/osx-x64/publish/perfs; don
real 0m38.211s
user 0m31.473s
sys 0m0.958s
```

```sh
$ python3
Python 3.7.5 (default, Nov 26 2019, 23:16:23)
$ time python3 perf.py
real 3m34.382s
user 3m21.708s
sys 0m1.565s
```
15 changes: 15 additions & 0 deletions perfs/python/perf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import random
import math
import sys

def Sum(a, b):
return a + b + random.randint(0,1024)#sys.maxsize)

def main():
sum = 0
for count in range(0, 10**8):
sum = Sum(sum, count)
return sum

if __name__ == "__main__":
main()

0 comments on commit 2d9735d

Please sign in to comment.