Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save 50n1cd347h9/0cc8def062ca3a886a5c553108d1d30b to your computer and use it in GitHub Desktop.

Select an option

Save 50n1cd347h9/0cc8def062ca3a886a5c553108d1d30b to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
from urllib.parse import urlparse, parse_qs
import sys

def grep_token(query_str):
    parsed_query = parse_qs(query_str)
    return parsed_query.get('token')[0]

def main(url):
    parsed_url = urlparse(url.replace("wss://", ""))
    new_url = "https://" + parsed_url.path.replace("/websocket-tunnel", "")
    new_url += "?token=" + grep_token(parsed_url.query)
    print(f"new url:\n{new_url}")
    #print(f"\npath: {parsed_url.path}")
    #print(f"\nquery: {parsed_url.query}")

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("usage: guac-urlfix.py <websocket url>")
        sys.exit(0)
    main(sys.argv[1])

Retrieve a url starts with wss:// from browser developer tools.

Then run following command:

./guac-urlfix.py "your vm url"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment