Skip to content

Commit

Permalink
pnet
Browse files Browse the repository at this point in the history
  • Loading branch information
nbari committed Dec 11, 2023
1 parent 0f5dd31 commit 5dc9640
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 2 deletions.
201 changes: 200 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ edition = "2018"
anyhow = "1"
clap = { version = "4", features = ["string", "env"] }
openssl = { version = "0.10", features = ["vendored"] }
pnet = "0.34.0"

[package.metadata]
publish = "vpn-kill-switch"
4 changes: 3 additions & 1 deletion src/cli/actions/default.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::cli::actions::Action;
use crate::killswitch;
use anyhow::Result;

/// Handle the create action
Expand All @@ -12,7 +13,8 @@ pub fn handle(action: Action) -> Result<()> {
local,
print,
} => {
todo!()
let info = killswitch::default()?;
println!("{}", info);
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/killswitch/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use anyhow::Result;

use pnet::datalink;

pub fn default() -> Result<String> {
let all_interfaces = datalink::interfaces();
let default_interface = all_interfaces
.iter()
.find(|e| e.is_up() && !e.is_loopback() && !e.ips.is_empty());

println!("{:#?}", default_interface);

Ok("".to_string())
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod cli;
pub mod killswitch;

0 comments on commit 5dc9640

Please sign in to comment.