Crate tianyi_api

source ·
Expand description

Tianyi API

tianyi_api is an unofficial API implementation for the China Telecom Tianyi router. It allows you to perform operations such as obtaining public IP addresses, updating port forwarding rules, and more.

This library provides an asynchronous API built with tokio and error handling with anyhow. It is designed to be simple to use and efficient.

Features

  • Get public IP address
  • Manage port forwarding rules (add, delete, enable, disable)
  • Retrieve gateway information
  • Logout from the router

Usage

Add this to your Cargo.toml:

[dependencies]
tokio = { version = "1.26", features = ["full"] }
tianyi_api = { git = "https://github.com/edsky/tianyi_api.git" }

Then, in your application, you can use the Tianyi struct to interact with the router:

use tianyi_api::TianyiBuilder;

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
    let tianyi = TianyiBuilder::new()
        .username("useradmin")
        .password("password")
        .build()
        .await?;

    let old_ip = "192.168.1.11";
    let new_ip = "192.168.1.12";
 
    tianyi_instance.update_port_forwarding_rule(old_ip, new_ip).await?;
 
    println!("Port forwarding rules updated successfully.");

    Ok(())
}

Examples

You can find examples for each operation in the examples directory of the GitHub repository.

Contributing

Contributions are welcome! Please feel free to open issues or submit pull requests on the GitHub repository.

License

This project is licensed under the MIT License.

Disclaimer

This library is not affiliated with, endorsed by, or supported by China Telecom or any other official entity. Use of this library is at your own risk. The authors and contributors are not responsible for any damage or issues that may arise from using this library.

Structs

  • Represents the gateway information returned by the router.
  • Represents the data returned by the router when retrieving a list of port forwarding rules.
  • Represents a port forwarding rule, including its properties and settings.
  • The Tianyi struct represents a connection to a Tianyi router and provides methods to interact with it.
  • TianyiBuilder is a builder for the Tianyi struct.

Enums

  • Represents the different actions that can be performed on a port forwarding rule.