View random ngrok URL when run in background

前端 未结 12 1710
旧时难觅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

    This little Python (2.7) script will call the ngrok API and print the current URL's:

    import json
    import os 
    
    os.system("curl  http://localhost:4040/api/tunnels > tunnels.json")
    
    with open('tunnels.json') as data_file:    
        datajson = json.load(data_file)
    
    
    msg = "ngrok URL's: \n'
    for i in datajson['tunnels']:
      msg = msg + i['public_url'] +'\n'
    
    print (msg)
    

提交回复
热议问题