From 490d34bd798d4a89f65dc6405f3e0af9d66500b6 Mon Sep 17 00:00:00 2001 From: Christian Ulrich Date: Wed, 18 Nov 2020 18:22:47 +0100 Subject: [PATCH] try continuous port range --- port_prediction.nim | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/port_prediction.nim b/port_prediction.nim index 5fca2bd..e6fac14 100644 --- a/port_prediction.nim +++ b/port_prediction.nim @@ -84,16 +84,13 @@ proc predictPortRange*(localPort: Port, probedPorts: seq[Port]): seq[Port] = return # assume symmetric NAT with random port mapping randomize() - let first = if minPort >= 1024 + 10000: - minPort - 10000 + let first = if maxPort <= uint16.high - RandomPortCount - 1000'u16: + maxPort + 1000'u16 else: - 1024 - let last = if maxPort <= uint16.high - 10000: - maxPort + 10000 - else: - uint16.high - for _ in 1 .. RandomPortCount: - result.add(Port(rand(first .. last))) + uint16.high - RandomPortCount + result = newSeq[Port](RandomPortCount) + for i in 0'u16 .. RandomPortCount - 1'u16: + result[i] = Port(first + i) suite "port prediction tests": test "single port":