Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How could I only print tunnels that use TCP protocol using the ngrok API in python?

Im quite new to Python and APIs, but anyway.

Im trying to only print out the running tunnels public url that use the TCP protocol from ngrok API.
I have got it to print all my running tunnels urls, but not specific protocols.

How could i modify this code to print only the TCP protocol tunnels public urls i have running?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import ngrok


client = ngrok.Client("API KEY HERE")

for tunnels in client.tunnels.list():
    print(tunnels.public_url)

I’m using this documentation

And this

>Solution :

Following the documentation of ngrok’s python api it seams that each tunnel has it’s proto property
https://python-api.docs.ngrok.com/datatypes.html#ngrok.datatypes.Tunnel.proto

for tunnel in client.tunnels.list():
  if tunnel.proto == 'tcp':
    print(tunnel.public_url)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading