Skip to content

Commit

Permalink
Added loading indicator cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
wizche committed Nov 29, 2019
1 parent 24f37ce commit 0346a07
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@
using System.Net;
using System.Net.NetworkInformation;
using DotNetProjects.DhcpServer;
using System.Threading.Tasks;

namespace dhcpshot
{
class Program
{
static void Main(string[] args)
static async Task LoadingIndicator()
{
char[] cursor = { '/', '-', '\\', '|' }; var idx = 0;
while (true)
{
Console.Write("{0,1}\b\b\b", cursor[(idx +=1) % cursor.Length]);
await Task.Delay(100);
}
}
static async Task Main(string[] args)
{
var rootCommand = new RootCommand
{
Expand All @@ -30,10 +40,10 @@ static void Main(string[] args)
};
rootCommand.Description = "DHCPshot - Assign IP address to first client asking on the specified interface";
rootCommand.Handler = CommandHandler.Create<string, string>(StartServer);
rootCommand.InvokeAsync(args).Wait();
await rootCommand.InvokeAsync(args);
}

public static void StartServer(string interfaceIp, string targetIp)
public static async void StartServer(string interfaceIp, string targetIp)
{
Console.WriteLine($"Looking for interface for IP {interfaceIp}");
var intf = NetworkInterface.GetAllNetworkInterfaces()
Expand Down Expand Up @@ -71,6 +81,7 @@ public static void StartServer(string interfaceIp, string targetIp)
server.SendDhcpAnswerNetworkInterface = intf;
server.Start();
Console.WriteLine("Running DHCP server... Press CTRL-C to exit");
await LoadingIndicator();
}

static void Request(DHCPRequest dhcpRequest, IPAddress targetIp)
Expand All @@ -81,13 +92,18 @@ static void Request(DHCPRequest dhcpRequest, IPAddress targetIp)
var replyOptions = new DHCPReplyOptions();
replyOptions.SubnetMask = IPAddress.Parse("255.255.255.0");

if (type == DHCPMsgType.DHCPDISCOVER){
if (type == DHCPMsgType.DHCPDISCOVER)
{
Console.WriteLine($"Received discovery, sending offer!");
dhcpRequest.SendDHCPReply(DHCPMsgType.DHCPOFFER, targetIp, replyOptions);
}else if (type == DHCPMsgType.DHCPREQUEST){
}
else if (type == DHCPMsgType.DHCPREQUEST)
{
Console.WriteLine($"Received request, sending ack!");
dhcpRequest.SendDHCPReply(DHCPMsgType.DHCPACK, targetIp, replyOptions);
} else {
}
else
{
Console.WriteLine($"Received unknown DHCP type {type}");
}
}
Expand Down

0 comments on commit 0346a07

Please sign in to comment.