12345678910111213141516171819202122232425262728293031 |
- package de.tudarmstadt.informatik.hostage;
- import de.tudarmstadt.informatik.hostage.logging.Logger;
- public class ConnectionGuard {
- private final static ConnectionGuard INSTANCE = new ConnectionGuard();
- private ConnectionGuard() {
- }
- private final static long ONE_SECOND_IN_NANOSECONDS = 1000000000;
- private static long lastTimestamp = 0;
- private static String lastIP = "";
- private static String lastProtocol = "";
- public static void registerConnection(String protocol, String ip) {
- long timestamp = System.nanoTime();
- boolean firstConnection = (lastTimestamp == 0);
- boolean belowThreshold = ((timestamp - lastTimestamp) < ONE_SECOND_IN_NANOSECONDS);
- boolean sameIP = (lastIP == ip);
- boolean sameProtocol = (lastProtocol == protocol);
- if (!firstConnection && sameIP && belowThreshold && !sameProtocol) {
- //TODO LOG PORTSCAN Logger.logPortscan(Hostage.getContext(), System.currentTimeMillis(), ip);
- }
- lastTimestamp = timestamp;
- lastIP = ip;
- lastProtocol = protocol;
- }
- }
|