Download cache/ProTrek/utils/server_tool.py from ppxscal/HiDRA-assets: direct link, hf CLI and curl.
- Browser
- Download file 983 Bytes
-
https://huggingface.co/datasets/ppxscal/HiDRA-assets/resolve/main/cache/ProTrek/utils/server_tool.py
- Command line
-
hf download hf://datasets/ppxscal/HiDRA-assets/cache/ProTrek/utils/server_tool.py
-
curl -L -o server_tool.py https://huggingface.co/datasets/ppxscal/HiDRA-assets/resolve/main/cache/ProTrek/utils/server_tool.py
983 Bytes
| import socket | |
| # Check whether a port is in use | |
| def check_port_in_use(port, host='127.0.0.1'): | |
| s = None | |
| try: | |
| s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| s.settimeout(1) | |
| s.connect((host, int(port))) | |
| return True | |
| except socket.error: | |
| return False | |
| finally: | |
| if s: | |
| s.close() | |
| # Get the IP address of the server | |
| def get_ip(): | |
| try: | |
| s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
| s.connect(('8.8.8.8', 80)) | |
| ip = s.getsockname()[0] | |
| finally: | |
| s.close() | |
| return ip | |
| # Check whether a server is active | |
| def check_port(ip, port): | |
| sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| sock.settimeout(1) | |
| try: | |
| result = sock.connect_ex((ip, port)) | |
| if result == 0: | |
| return True | |
| else: | |
| return False | |
| except Exception as e: | |
| print(e) | |
| return False | |
| finally: | |
| sock.close() |