Skip to content

Commit

Permalink
This is the end
Browse files Browse the repository at this point in the history
  • Loading branch information
D2ceCube committed Nov 16, 2023
1 parent 4293211 commit 05d8bb0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
25 changes: 23 additions & 2 deletions dhcp-stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void print_traffic_online() {
cbreak();
noecho();
curs_set(false);
WINDOW *win = newwin(10, 40, 0, 0);
WINDOW *win = newwin(10, 70, 0, 0);
refresh();
scrollok(win, true);

Expand All @@ -172,11 +172,24 @@ void print_traffic_online() {

// Print it
mvwprintw(win, row, 0, "%s %d %d %.2f%%\n", prefix.second.prefix.c_str(), prefix.second.max_hosts, prefix.second.allocated_addresses, prefix.second.util_percent);

row++;

// refresh windows
wrefresh(win);
}

row += 2; // for more space to make it readable
// Print if utilization is more than 50% in window
for (auto &prefix : stats_map) {
if (prefix.second.util_percent >= 50) {
mvwprintw(win, row, 0, "Prefix %s exceeded 50%% of allocations.", prefix.second.prefix.c_str());
row++;
// refresh windows
wrefresh(win);
}
}

// Wait 150ms
napms(150);
}

Expand All @@ -192,6 +205,14 @@ void print_traffic_offline() {
for (auto &prefix : stats_map) {
printf("%s %d %d %.2f%%\n", prefix.second.prefix.c_str(), prefix.second.max_hosts, prefix.second.allocated_addresses, prefix.second.util_percent);
}

printf("\n");
// Now print if utilization is more than 50%
for (auto &prefix : stats_map) {
if (prefix.second.util_percent >= 50) {
printf("Prefix %s exceeded 50%% of allocations.\n", prefix.second.prefix.c_str());
}
}
}


Expand Down
Binary file modified manual.pdf
Binary file not shown.
4 changes: 2 additions & 2 deletions test/dhcp_scapy.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from scapy.all import *

yiaddr_addr = "192.168.0."
yiaddr_addr = ""

x = 0
while x < 2:
while x < 10:
yiaddr_addr = "192.168.0." + str(x)
dhcp_ack_1 = Ether(dst="ff:ff:ff:ff:ff:ff") / IP(src="0.0.0.0", dst="255.255.255.255") / UDP(sport=67, dport=68) / \
BOOTP(op=2, xid=0x01020304, yiaddr=yiaddr_addr) / DHCP(options=[("message-type", "ack"), ("subnet_mask", "255.255.255.0"), "end"])
Expand Down

0 comments on commit 05d8bb0

Please sign in to comment.