Skip to content

Instantly share code, notes, and snippets.

@rvalieris
Created August 23, 2019 14:47
Show Gist options
  • Save rvalieris/30f86719047d9260ce5e0fef8e64f36f to your computer and use it in GitHub Desktop.
Save rvalieris/30f86719047d9260ce5e0fef8e64f36f to your computer and use it in GitHub Desktop.
find a unused port on linux
import psutil
import random
ports = set(map(lambda k: k.laddr.port,psutil.net_connections()))
print(random.choice(list(set(range(2000,10000)) - ports)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment