Created
July 31, 2014 23:18
-
-
Save leepro/b4e754965768ddcd1862 to your computer and use it in GitHub Desktop.
find a open port
This file contains hidden or 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
| def get_open_port(): | |
| import socket | |
| s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| s.bind(("", 0)) | |
| s.listen(1) | |
| port = s.getsockname()[1] | |
| s.close() | |
| return port |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment