RingLinkRingLink
Python

将 Python 服务暴露到 RingLink

RingLink Python SDK 是一个库,允许您将 RingLink 网状网络功能嵌入到您的 Python 应用程序中。 您可以通过编程方式连接到您的 RingLink 网络,例如, 访问网络上的其他设备或将本地服务发布到 RingLink 网络。

RingLink SDK 基于用户空间 TCP/IP 堆栈构建, 开发人员无需修改系统网络设置或需要提升权限。 这使得连接到现有 RingLink 网络变得灵活。

当前的 RingLink Python SDK 处于 alpha 阶段。 其功能不完整,API 可能会发生变化。

功能特性

  • IPv4
  • IPv6(隧道中)
  • 传入 TCP 代理
  • TCP 服务器和客户端
  • UDP

开始使用

在 Python 中使用 RingLink SDK 非常简单,只需安装 ringlink 包。

pip install ringlink

要求

在使用 RingLink Python SDK 之前,请确保您满足以下要求:

  • Python 3.9 或更高版本
  • 配置密钥

示例

通过代理将本地服务发布到 RingLink 网络:

import asyncio
from ringlink import auto

async def main():
    stack = await auto("53cd98d2", "<your-config-key>")
    with stack.tcp_proxy("0.0.0.0:80", "127.0.0.1:8000"):
        # run your server here, typically a web server run forever
        pass


asyncio.run(main())

In this code, a RingLink instance is first created using the auto function, passing your config key and network ID. Then, RingLink.tcp_proxy is used to create a proxy tunnel. The first parameter is the local address and port to listen on (usually 0.0.0.0), and the second is the address and port of the service to be published.

When this code runs, RingLink automatically creates a TCP proxy tunnel. Other devices on the current RingLink network accessing <private-ip>:80 will be forwarded to the local 127.0.0.1:8000.