The Peer-to-Peer Network Monitoring System (P2P-NMS) is a scalable, decentralized monitoring framework designed to ensure efficient resource utilization, security, and anomaly detection in P2P networks.
- SkyEye KOM Tree Topology for hierarchical scalability (up to 1000 peers)
- AES-256 Encrypted Communications for GDPR compliance
- Honeypot + ML-based Anomaly Detection (Isolation Forest) for threat mitigation
- Dynamic Peer Monitoring for CPU, bandwidth, and storage metrics
- Capacity-based Query Processing for optimized peer selection
P2P_Network_Monitoring/
βββ coordinator.py # Coordinator (Server) - Aggregates attributes, processes queries
βββ peer.py # Peer Node (Client) - Sends attributes, requests peers
βββ honeypot.py # Honeypot trap for malicious peers
βββ network.py # SkyEye KOM topology emulation (Mininet)
βββ utils.py # Shared encryption, logging, utilities
βββ logs/ # Log files directory (created automatically)
βββ coordinator.key # Encryption key file (created by coordinator)
βββ README.md # Project documentation
- Python: 3.8+
- Supported OS:
- Linux (best performance & full Mininet support)
- Windows (with WSL2 for Mininet)
- macOS (local tests only; Mininet partial support)
Important: This project requires a virtual environment due to macOS package management restrictions.
# Create and activate virtual environment
python3 -m venv venv
source venv/bin/activate # On macOS/Linux
# or
venv\Scripts\activate # On Windows
# Install required libraries
pip install pycryptodome scikit-learn psutil mininetNote:
- Mininet typically requires
sudoon Linux systems for proper network interface access - The
pycryptodomepackage is required for AES encryption functionality - Virtual environment is mandatory on macOS due to system package restrictions
# Create virtual environment
python3 -m venv venv
# Activate virtual environment
source venv/bin/activate # macOS/Linux
# or
venv\Scripts\activate # Windows
# Install dependencies
pip install pycryptodome scikit-learn psutil mininet# Make sure virtual environment is activated
source venv/bin/activate
# Start coordinator
python3 coordinator.py- Listens on port 5001 for peer connections
- Creates
coordinator.keyfile for encryption - Creates
logs/coordinator.logfor logging - Aggregates metrics and detects anomalies
- Redirects suspicious peers to the honeypot
# In a new terminal, activate virtual environment
source venv/bin/activate
# Start honeypot
python3 honeypot.py- Listens on port 9999
- Creates
logs/honeypot.logfor logging - Logs all malicious traffic attempts
# In a new terminal, activate virtual environment
source venv/bin/activate
# Start a peer with unique ID
python3 peer.py <peer_id>- Replace
<peer_id>with a unique identifier for each peer (e.g.,peer_1,peer_2) - Sends CPU, bandwidth, and storage metrics every 10 seconds
- Communicates with the Coordinator using AES-256 encryption
- Creates
logs/peer_<peer_id>.logfor logging
Example - Running multiple peers:
# Terminal 1: Coordinator
source venv/bin/activate
python3 coordinator.py &
# Terminal 2: Honeypot
source venv/bin/activate
python3 honeypot.py &
# Terminal 3: Peers
source venv/bin/activate
python3 peer.py peer_1 &
python3 peer.py peer_2 &Requires Linux or WSL2 and root privileges
sudo python3 network.pySimulates a hierarchical P2P network with coordinators and peers.
- Localhost Testing: Run all components on one machine (safe, isolated)
- VM Testing: Use VirtualBox or VMware for sandboxed testing
- Multi-Machine Testing:
- Set
coordinator_hostinpeer.pyto the server machine's IP - Open TCP ports 5001 & 9999 on the host firewall
- Set
Common Issues:
-
"No module named 'Crypto'" error:
- Ensure virtual environment is activated:
source venv/bin/activate - Reinstall pycryptodome:
pip install --upgrade pycryptodome
- Ensure virtual environment is activated:
-
"Address already in use" error:
- Kill existing processes:
pkill -f python3 - Or use different ports by modifying the port numbers in the code
- Kill existing processes:
-
"Could not connect to coordinator" error:
- Ensure coordinator is running first
- Check if
coordinator.keyfile exists - Verify port 5001 is not blocked by firewall
| Scenario | How to Test | Expected Output |
|---|---|---|
| Normal Operation | Run coordinator + peer | logs/coordinator.log: Attribute updates from peers |
| Attack Simulation (DDoS) | Modify peer.py to send 100+ queries/sec |
logs/honeypot.log: Malicious activity detected and logged |
| Network Churn | Start 3 peers, abruptly stop one (Ctrl+C) | logs/coordinator.log: Peer disconnected due to timeout |
| Cross-OS Setup | Run coordinator on Linux, peers on Windows/macOS | Successful connections and query responses |
| Resource Optimization | Multiple peers with varied capacities, send queries | Optimized peer selection with lowest latency and highest capacity |
logs/coordinator.logβ Peer updates, query results, anomaly detection eventslogs/honeypot.logβ Captures all malicious traffic attemptslogs/peer_<id>.logβ Records peer's sent attributes and responses
2025-08-06 00:34:08,561: Coordinator started on 0.0.0.0:5001
2025-08-06 00:34:08,562: Encryption key saved to coordinator.key
2025-08-06 00:34:08,562: Coordinator running...
2025-08-06 00:35:00,172: New connection from ('127.0.0.1', 51934)
2025-08-06 00:35:04,346: Received packet from ('127.0.0.1', 51934): attribute_update
2025-08-06 00:35:04,349: Updated attributes for peer test_peer_1- Decentralized monitoring for large-scale networks
- Low-latency query response (50β65 ms for 1000 peers)
- <1% packet loss tolerance
- Isolation Forest ML model (trained on 10,000 samples)
- AES-256 encryption for GDPR compliance
- Honeypot redirection to isolate malicious actors
- Virtual Environment Required: Always activate the virtual environment before running any component
- Port Configuration:
- Coordinator runs on port 5001 (not 5000 as in original design)
- Honeypot runs on port 9999
- Key Exchange: The coordinator creates
coordinator.keyfile for peer encryption - Logging: All logs are stored in the
logs/directory
This implementation is for academic and research purposes only. Keys are exchanged via file sharing in this prototype; do not use in production without proper security audits and thorough testing.
This project is intended for educational and research use. Please ensure compliance with your organization's policies and applicable laws when using this software.
This is a research project. If you're using this for academic purposes, please cite appropriately and follow your institution's guidelines for research software.