Getting list of open/exposed ports

Hello,

I am building an extension and I need to get all ports on which http server is running.
I see, gitpod has open ports tab. How can I access this information ?
I checked environment variables as well as gitpod cli. But I could not find any mechanism that can return me this information.

Hi @UtsavChokshiCNU!

To know which ports are “open” (or “active” / “being listened on”), you could read /proc/net/tcp and /proc/net/tcp6. That’s what Gitpod and the gp CLI do to know on which ports something (e.g. http server) is listening on.

Note: The ports are encoded in hexadecimal (which you may want to convert to decimal), and the relevant connection state is 0A (a.k.a. TCP_LISTEN).

For example, here is the implement of gp await-port <PORT> (in Go):

1 Like

Also, I’m told that there is a new upcoming PortsStatus Gitpod API that should get released soon and will provide more information on exposed & active ports in Gitpod:

Once this gets released (in a few weeks or so) you should be able to query a URL like localhost:22999/v1/status/ports/observe/true in a Gitpod workspace (e.g. with curl) and get a steady stream of port status updates.

(Thanks @csweichel for the hint!)

2 Likes