Skip to content

Commit

Permalink
恢复 detectPort
Browse files Browse the repository at this point in the history
  • Loading branch information
moeshin committed Apr 2, 2023
1 parent bf499aa commit c69524f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions utils/port.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import requests
import socket


def detectPort(port=6666):
if not port:
return False

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
return requests.head("http://127.0.0.1:%d/ocr/api" % port, timeout=2).headers.get("Dango-OCR") == "OK"
s.connect(("127.0.0.1", int(port)))
s.shutdown(2)
sign = True
except Exception:
return False
sign = False
s.close()

return sign

0 comments on commit c69524f

Please sign in to comment.