Created
June 4, 2017 04:15
-
-
Save FingerLiu/d7389e911b5305931028b8ad4a6be93d to your computer and use it in GitHub Desktop.
获取一个未使用的端口
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