mirror of
https://github.com/The-Art-of-Hacking/h4cker.git
synced 2024-12-25 07:09:40 -05:00
Merge pull request #252 from The-Art-of-Hacking/revert-251-patch-1
Revert "packet defender". The file needs to be organized better.
This commit is contained in:
commit
fbbdfbc57f
@ -1,55 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
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<std::string> 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<Packet> 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;
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user