Created
August 23, 2019 14:47
-
-
Save rvalieris/30f86719047d9260ce5e0fef8e64f36f to your computer and use it in GitHub Desktop.
find a unused port on linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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