Crates.io | tauri-plugin-network |
lib.rs | tauri-plugin-network |
version | 2.0.4 |
source | src |
created_at | 2023-08-17 18:53:20.102506 |
updated_at | 2024-10-03 15:50:21.306863 |
description | A tauri plugin for retrieving system info |
homepage | |
repository | https://github.com/HuakunShen/tauri-plugin-network.git |
max_upload_size | |
id | 947337 |
size | 85,440 |
This is a Tauri plugin for reading network interface information and scanning network.
If you are installing from npm and crate.io package registry, make sure the versions for both packages are the same, otherwise, the API may not match.
cargo add tauri-plugin-network
to add the package.
Or add the following to your Cargo.toml
for the latest unpublished version (not recommanded).
tauri-plugin-network = { git = "https://github.com/HuakunShen/tauri-plugin-network", branch = "main" }
Run the following to install JavaScript/TypeScript API package.
npm i tauri-plugin-network-api
# npm add https://github.com/HuakunShen/tauri-plugin-network # or this for latest unpublished version (not recommended)
In main.rs
, add the following to your tauri::Builder
:
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_network::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
All TypeScript APIs can be found in api.ts.
Return type of each API is added. The object structures can be found in types.ts.
Valibot was used to define type schema and infer TypeScript types. You can import the types exported from the npm package.
The exported valibot schemas can be used to parse data and make sure the data returned from rust APIs match the desired structure defined in schema.
import { getInterfaces, NetworkInterface } from "tauri-plugin-network-api";
function getInterfacesOnClick() {
getInterfaces().then((ifaces: Array<Object>) => {
const parsed = z.array(NetworkInterface).safeParse(ifaces);
if (parsed.success) {
data = JSON.stringify(parsed.data, null, 2);
} else {
error = parsed.error.toString();
}
});
}
import {
isHttpPortOpen,
isPortTaken,
findAvailablePort,
scanOnlineIpPortPairs,
scanOnlineIpsByPort,
nonLocalhostNetworks,
localServerIsRunning,
scanLocalNetworkOnlineHostsByPort,
} from "tauri-plugin-network-api";
console.log(await is_http_port_open("127.0.0.1", 8000));
console.log(await isPortTaken(8000));
console.log(await findAvailablePort());
console.log(
await scanOnlineIpPortPairs([
{ ip: "127.0.0.1", port: 8000 },
{ ip: "192.168.3.6", port: 8000 },
{ ip: "192.168.3.5", port: 8000 },
])
);
console.log(
await scanOnlineIpsByPort(["127.0.0.1", "192.168.3.6", "192.168.1.2"], 8000)
);
console.log("Non Localhost Networks", await nonLocalhostNetworks());
console.log("Local Server is Running", await localServerIsRunning(8000));
console.log(
"Scan Local Network for service",
await scanLocalNetworkOnlineHostsByPort(8000, "AppName")
);
See SvelteKit Example for an example written with SvelteKit.