Created
August 21, 2025 08:44
-
-
Save guillaumefalvet/f2f470dc0914aed03ef8ce89b97553d6 to your computer and use it in GitHub Desktop.
HMI DETECTION URL
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
| import subprocess | |
| import re | |
| def get_node_server_url(): | |
| # Execute the command to find processes listening on ports | |
| result = subprocess.run(['lsof', '-i', '-P', '-n'], stdout=subprocess.PIPE, text=True) | |
| output = result.stdout | |
| # Search for Node.js processes and extract the port number | |
| matches = re.findall(r'node.*:(\d{5}) \(LISTEN\)', output) | |
| if matches: | |
| # Assuming you want the first match | |
| port = matches[0] | |
| url = f"localhost:{port}/" | |
| print(url) | |
| else: | |
| print("Node server port not found.") | |
| get_node_server_url() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment