Added manual specification of interfaces
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
use std::{fs, io};
|
||||
use std::net::IpAddr;
|
||||
use std::path::Path;
|
||||
use if_addrs::{Interface, get_if_addrs};
|
||||
|
||||
pub fn print_single_interface<P: AsRef<Path>>(iface: Interface, path: P) -> io::Result<()> {
|
||||
fn print_single_interface<P: AsRef<Path>>(iface: Interface, path: P) -> io::Result<()> {
|
||||
for entry in fs::read_dir(path)? {
|
||||
let entry = entry?;
|
||||
let entry_path = entry.path();
|
||||
@@ -16,10 +17,21 @@ pub fn print_single_interface<P: AsRef<Path>>(iface: Interface, path: P) -> io::
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn print_all_interface<P: AsRef<Path>>(path: P) {
|
||||
fn is_last_octet_one(ip: IpAddr) -> bool {
|
||||
match ip {
|
||||
IpAddr::V4(addr) => addr.octets()[3] == 1,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_interface<P: AsRef<Path>>(iface_str: &str, path: P) {
|
||||
for iface in get_if_addrs().unwrap() {
|
||||
if iface.is_loopback() {
|
||||
continue
|
||||
if iface_str == "all" {
|
||||
if iface.is_loopback() || is_last_octet_one(iface.ip()) {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
if iface_str != iface.name { continue }
|
||||
}
|
||||
|
||||
print_single_interface(iface, &path).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user