summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.rs14
-rw-r--r--src/error.rs6
-rw-r--r--src/main.rs8
-rw-r--r--src/netlink.rs3
-rw-r--r--src/scanner.rs8
5 files changed, 30 insertions, 9 deletions
diff --git a/src/config.rs b/src/config.rs
index 5d49042..e7ee2e9 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -14,13 +14,17 @@ pub struct Config {
#[arg(short, long)]
pub port: Option<u16>,
- /// wait <TIMEOUT> (ms) when checking for open ports in ms (requires --port=<PORT>)
- #[arg(short, long, default_value_t = 250, requires = "port")]
+ /// <TIMEOUT> (ms) used for ICMP (or TCP when using --port=<PORT>)
+ #[arg(short, long, default_value_t = 250)]
pub timeout: u64,
- /// Discover hosts on <NETWORK> with <PORT> (requires --port=<PORT>)
- #[arg(short, long, id = "NETWORK", requires = "port")]
- pub scan: Option<IpNet>,
+ /// Include network neighbours
+ #[arg(short, long)]
+ pub neigh: bool,
+
+ /// Discover hosts on <NETWORK>
+ #[arg(short, long, id = "NETWORK")]
+ pub scan: Option<Option<IpNet>>,
/// include <NAME>. If <NAME> is a valid path or '-', hosts with be read from the file or
/// stdin, respectivly.
diff --git a/src/error.rs b/src/error.rs
index e98fe68..048440c 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -10,6 +10,12 @@ pub enum Error {
#[error("IO error: {0}")]
IO(#[from] std::io::Error),
+ #[error("Local IP error: {0}")]
+ LocalIp(#[from] local_ip_address::Error),
+
+ #[error("IpNet error: {0}")]
+ IpNet(#[from] ipnet::PrefixLenError),
+
#[error("Join error: {0}")]
Join(#[from] tokio::task::JoinError),
diff --git a/src/main.rs b/src/main.rs
index 6f60514..529c1ed 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -15,6 +15,8 @@ use tokio::{
mod config;
+const PAYLOAD: [u8; 8] = [0; 8];
+
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
let config = Config::parse();
@@ -53,7 +55,9 @@ async fn main() -> Result<(), anyhow::Error> {
let cache = Arc::new(Mutex::new(cache));
let names = Arc::new(Mutex::new(names));
- join_set.spawn(sshr::netlink::neighbours(tx.clone()));
+ if config.neigh {
+ join_set.spawn(sshr::netlink::neighbours(tx.clone()));
+ }
if let Some(ip_net) = config.scan {
join_set.spawn(sshr::scanner::scan(tx.clone(), ip_net));
@@ -76,6 +80,8 @@ async fn main() -> Result<(), anyhow::Error> {
if block_in_place(|| TcpStream::connect_timeout(&addr, timeout)).is_err() {
return Ok(());
}
+ } else if surge_ping::ping(ip_addr, &PAYLOAD).await.is_err() {
+ return Ok(());
}
if let Some(s) = config.resolve.then(|| lookup_addr(&ip_addr).ok()).flatten() {
diff --git a/src/netlink.rs b/src/netlink.rs
index 2945a09..9e21dbc 100644
--- a/src/netlink.rs
+++ b/src/netlink.rs
@@ -1,8 +1,7 @@
-use std::{collections::HashSet, net::IpAddr};
+use std::net::IpAddr;
use futures::stream::TryStreamExt;
use netlink_packet_route::{
- address::AddressAttribute,
neighbour::{NeighbourAddress, NeighbourAttribute, NeighbourMessage, NeighbourState},
route::RouteType,
};
diff --git a/src/scanner.rs b/src/scanner.rs
index fa801e5..c51dffc 100644
--- a/src/scanner.rs
+++ b/src/scanner.rs
@@ -5,7 +5,13 @@ use tokio::{sync::mpsc::Sender, task::JoinSet};
use crate::Result;
-pub async fn scan(tx: Sender<IpAddr>, ip_net: IpNet) -> Result<()> {
+pub async fn scan(tx: Sender<IpAddr>, ip_net: Option<IpNet>) -> Result<()> {
+ let ip_net = match ip_net {
+ Some(net) if !net.addr().is_unspecified() => net,
+ Some(net) => IpNet::new(local_ip_address::local_ip()?, net.prefix_len())?,
+ None => IpNet::new(local_ip_address::local_ip()?, 24)?,
+ };
+
let mut join_set = JoinSet::new();
for ip_addr in ip_net.hosts() {
let tx = tx.clone();