package de.tudarmstadt.informatik.hostage; import android.util.Log; 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; public static void registerConnection() { long timestamp = System.nanoTime(); boolean firstConnection = (lastTimestamp == 0); boolean belowThreshold = ((timestamp - lastTimestamp) < ONE_SECOND_IN_NANOSECONDS); if (!firstConnection && belowThreshold) { Log.d("ConnectionGuard", "PORTSCAN DETECTED"); } lastTimestamp = timestamp; } }