21 lines
404 B
Python
21 lines
404 B
Python
#!/usr/bin/env python3
|
|
import socket
|
|
|
|
START, END = 8000, 8100
|
|
|
|
def port_free(port):
|
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|
try:
|
|
s.bind(("0.0.0.0", port))
|
|
return True
|
|
except OSError:
|
|
return False
|
|
|
|
for port in range(START, END + 1):
|
|
if port_free(port):
|
|
print(port)
|
|
exit(0)
|
|
|
|
print("ERR_NO_FREE_PORT")
|
|
exit(1)
|