https://github.com/HuakunShen/tauri-plugin-network
Tauri plugin for network (scanning, detection)
https://github.com/HuakunShen/tauri-plugin-network
Last synced: 18 days ago
JSON representation
Tauri plugin for network (scanning, detection)
- Host: GitHub
- URL: https://github.com/HuakunShen/tauri-plugin-network
- Owner: HuakunShen
- License: mit
- Created: 2023-08-14T09:17:03.000Z (almost 2 years ago)
- Default Branch: v2
- Last Pushed: 2025-03-26T05:58:40.000Z (2 months ago)
- Last Synced: 2025-04-15T15:47:23.375Z (about 2 months ago)
- Language: Rust
- Size: 597 KB
- Stars: 32
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-tauri - tauri-plugin-network - Tools for reading network information and scanning network. (Development / Plugins)
README
# Tauri Plugin network

### API Documentation: https://huakunshen.github.io/tauri-plugin-network/
> This is a Tauri plugin for reading network interface information and scanning network.
- Tauri v1 support on branch v1 (package version 1.x)
- Tauri v2 support on branch v2 (package version 2.x)## Features
- [x] Retrieve network interface information
- [x] TCP host up detection
- [x] Scan local network ips on specified port using HTTP
- [x] With optional response keyword detection
- [x] Batch scanning with multi-threading
- [ ] ICMP scan
- [ ] Network data transmission monitoring
- [ ] Packet sniffing (This is harder on Windows as [pnet](https://crates.io/crates/pnet) on Windows requires installation of WinPcap or npcap)## Installation
> 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.
### Rust Install
`cargo add tauri-plugin-network` to add the package.
Or add the following to your `Cargo.toml` for the latest unpublished version (not recommanded).
```toml
tauri-plugin-network = { git = "https://github.com/HuakunShen/tauri-plugin-network", branch = "main" }
```### NPM Install
Run the following to install JavaScript/TypeScript API package.
```bash
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`:
```rust
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_network::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
```## Third Party Libraries Used
- [`network-interface`](https://crates.io/crates/network-interface)
## API
### TypeScript
All TypeScript APIs can be found in [api.ts](./webview-src/api.ts).
Return type of each API is added. The object structures can be found in [types.ts](./webview-src/types.ts).
Zod was used to define type schema and infer TypeScript types. You can import the types exported from the npm package.
The exported zod schemas can be used to parse data and make sure the data returned from rust APIs match the desired structure defined in schema.
#### Get Interface Info
```typescript
import { getInterfaces, NetworkInterface } from "tauri-plugin-network-api";function getInterfacesOnClick() {
getInterfaces().then((ifaces: Array) => {
const parsed = z.array(NetworkInterface).safeParse(ifaces);
if (parsed.success) {
data = JSON.stringify(parsed.data, null, 2);
} else {
error = parsed.error.toString();
}
});
}
```#### Scanning
```typescript
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")
);
```## Usage
See [SvelteKit Example](./examples/sveltekit/README.md) for an example written with SvelteKit.