logout and port forwarding

This commit is contained in:
lemonsh
2023-05-04 23:10:17 +02:00
parent 5e7a3adafa
commit 33508a9732
5 changed files with 176 additions and 32 deletions

View File

@ -1,7 +1,10 @@
use std::env;
use std::{env, net::Ipv4Addr};
use color_eyre::Result;
use connectbox::ConnectBox;
use connectbox::{
models::{PortForwardEntry, PortForwardProtocol},
ConnectBox, PortForwardAction,
};
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
@ -14,8 +17,32 @@ async fn main() -> Result<()> {
let connect_box = ConnectBox::new(ip, code, true)?;
connect_box.login().await?;
let devices = connect_box.get_devices().await?;
println!("{devices:#?}");
connect_box
.edit_port_forwards(|v| {
if v.local_ip == Ipv4Addr::new(192, 168, 0, 180) {
PortForwardAction::Delete
} else {
PortForwardAction::Keep
}
})
.await?;
let pf = PortForwardEntry {
id: 0,
local_ip: "192.168.0.180".parse().unwrap(),
start_port: 25565,
end_port: 25565,
start_port_in: 25565,
end_port_in: 25565,
protocol: PortForwardProtocol::Both,
enable: true,
};
connect_box.add_port_forward(&pf).await?;
let portforwards = connect_box.port_forwards().await?;
println!("{portforwards:#?}");
connect_box.logout().await?;
Ok(())
}