2 releases
0.1.1 | Nov 1, 2023 |
---|---|
0.1.0 | Aug 5, 2023 |
81 downloads per month
Used in upnp-daemon
16KB
145 lines
easy-upnp
Easily open and close UPnP ports.
A minimalistic wrapper around IGD to open and close network ports via
UPnP. Mainly this library is used in the CLI application upnp-daemon
,
but it can also be used as a library in other crates that just want to open
and close ports with minimal possible configuration.
Example
Here is a hands-on example to demonstrate the usage. It will add some ports and immediately remove them again.
use std::error::Error;
use cidr_utils::cidr::Ipv4Cidr;
use easy_upnp::{add_ports, delete_ports, PortMappingProtocol, UpnpConfig};
fn get_configs() -> Result<[UpnpConfig; 3], Box<dyn Error>> {
let config_no_address = UpnpConfig {
address: None,
port: 80,
protocol: PortMappingProtocol::TCP,
duration: 3600,
comment: "Webserver".to_string(),
};
let config_specific_address = UpnpConfig {
address: Some(Ipv4Cidr::from_str("192.168.0.10/24")?),
port: 8080,
protocol: PortMappingProtocol::TCP,
duration: 3600,
comment: "Webserver alternative".to_string(),
};
let config_address_range = UpnpConfig {
address: Some(Ipv4Cidr::from_str("192.168.0")?),
port: 8081,
protocol: PortMappingProtocol::TCP,
duration: 3600,
comment: "Webserver second alternative".to_string(),
};
Ok([
config_no_address,
config_specific_address,
config_address_range,
])
}
fn main() -> Result<(), Box<dyn Error>> {
add_ports(get_configs()?);
delete_ports(get_configs()?);
Ok(())
}
Dependencies
~6–8MB
~179K SLoC