Skip to content

Instantly share code, notes, and snippets.

@guillaumefalvet
Created August 21, 2025 08:44
Show Gist options
  • Select an option

  • Save guillaumefalvet/f2f470dc0914aed03ef8ce89b97553d6 to your computer and use it in GitHub Desktop.

Select an option

Save guillaumefalvet/f2f470dc0914aed03ef8ce89b97553d6 to your computer and use it in GitHub Desktop.
HMI DETECTION URL
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