Skip to content

Instantly share code, notes, and snippets.

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