From 48661008ab4e44f1c14277383f4a97e95637ed14 Mon Sep 17 00:00:00 2001 From: Vijay Yadav <135238089+vijayleo31@users.noreply.github.com> Date: Fri, 13 Dec 2024 23:33:13 +0530 Subject: [PATCH] packet defender --- packet defender | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 packet defender diff --git a/packet defender b/packet defender new file mode 100644 index 0000000..abc3594 --- /dev/null +++ b/packet defender @@ -0,0 +1,55 @@ +#include +#include +#include +#include + +class Packet { +public: + std::string sourceIP; + std::string destinationIP; + int port; + + Packet(std::string src, std::string dest, int p) + : sourceIP(src), destinationIP(dest), port(p) {} +}; + +class PacketFilter { +private: + std::vector blockedIPs; + +public: + void addBlockedIP(const std::string& ip) { + blockedIPs.push_back(ip); + } + + bool isBlocked(const Packet& packet) { + return std::find(blockedIPs.begin(), blockedIPs.end(), packet.sourceIP) != blockedIPs.end(); + } + + void processPacket(const Packet& packet) { + if (isBlocked(packet)) { + std::cout << "Blocked packet from: " << packet.sourceIP << std::endl; + } else { + std::cout << "Allowed packet from: " << packet.sourceIP << std::endl; + } + } +}; + +int main() { + PacketFilter filter; + filter.addBlockedIP("192.168.1.10"); + filter.addBlockedIP("10.0.0.5"); + + std::vector packets = { + Packet("192.168.1.10", "192.168.1.1", 80), + Packet("10.0.0.5", "192.168.1.2", 443), + Packet("192.168.1.20", "192.168.1.3", 22), + Packet("172.16.0.1", "192.168.1.4", 8080) + }; + + for (const auto& packet : packets) { + filter.processPacket(packet); + } + + return 0; +}