View random ngrok URL when run in background

前端 未结 12 1725
旧时难觅i
旧时难觅i 2021-02-02 08:16

When I start an ngrok client with ./ngrok tcp 22 it runs in the foreground and I can see the randoming generated forwarding URL, such as tcp://0.tcp.ngrok.io:

12条回答
  •  难免孤独
    2021-02-02 08:27

    In Python3

    import json
    import requests
    
    
    def get_ngrok_url():
        url = "http://localhost:4040/api/tunnels"
        res = requests.get(url)
        res_unicode = res.content.decode("utf-8")
        res_json = json.loads(res_unicode)
        return res_json["tunnels"][0]["public_url"]
    

    This returned json have 2 url for http and https. If you want only https url, you res_json["tunnels"][index num]["proto"]

提交回复
热议问题