TCP Listener Builder#

The ngrok Agent SDK for Python

class ngrok.TcpListenerBuilder#

An ngrok listener backing a TCP endpoint.

allow_cidr(cidr)#

Restriction placed on the origin of incoming connections to the edge to only allow these CIDR ranges. Call multiple times to add additional CIDR ranges. See IP restrictions in the ngrok docs for additional details.

deny_cidr(cidr)#

Restriction placed on the origin of incoming connections to the edge to deny these CIDR ranges. Call multiple times to add additional CIDR ranges. See IP restrictions in the ngrok docs for additional details.

forwards_to(forwards_to)#

Listener backend metadata. Viewable via the dashboard and API, but has no bearing on listener behavior.

To automatically forward connections, you can use listen_and_forward, or listen_and_serve on the Listener Builder.

listen()#

Begin listening for new connections on this listener.

listen_and_forward(to_url)#

Begin listening for new connections on this listener and forwarding them to the given url. This url can be either a TCP/HTTP address or a file socket path, for example: “http://localhost:8080”, “https://192.168.1.100:8443”, or for file socket paths on Linux/Darwin “unix:///path/to/unix.sock”.

Parameters:

to_url – The URL to forward traffic on to

Returns:

A task to await for the Listener linked with the server.

Return type:

Task

listen_and_serve(server)#

Begin listening for new connections on this listener and forwarding them to the given http server.

Parameters:

server (http.server.HTTPServer or None) – The server to link with a Listener.

Returns:

A task to await for the Listener linked with the server.

Return type:

Task

metadata(metadata)#

Listener-specific opaque metadata. Viewable via the API.

policy(policy_config)#

Traffic Policy configuration. :param str policy_config: Traffic policy configuration to be attached to the listener.

proxy_proto(proxy_proto)#

The version of PROXY protocol to use with this listener “1”, “2”, or “” if not using.

remote_addr(remote_addr)#

The TCP address to request for this edge. These addresses can be reserved in the ngrok dashboard to use across sessions. For example: remote_addr(“2.tcp.ngrok.io:21746”)

verify_upstream_tls(verify_upstream_tls)#

Whether to disable certificate verification for this listener.