mirror of
https://github.com/ivre/masscanned.git
synced 2025-10-02 06:38:21 +00:00
Add option for list of IP to bind in command-line argument
This commit is contained in:
parent
851a418add
commit
726b5d2e87
2 changed files with 56 additions and 4 deletions
|
@ -116,18 +116,23 @@ fn main() {
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("mac")
|
Arg::new("mac")
|
||||||
.short('a')
|
.short('m')
|
||||||
.long("mac-addr")
|
.long("mac-addr")
|
||||||
.help("MAC address to use in the response packets")
|
.help("MAC address to use in the response packets")
|
||||||
.takes_value(true),
|
.takes_value(true),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("ip")
|
Arg::new("ipfile")
|
||||||
.short('f')
|
|
||||||
.long("ip-addr-file")
|
.long("ip-addr-file")
|
||||||
.help("File with the list of IP addresses to impersonate")
|
.help("File with the list of IP addresses to impersonate")
|
||||||
.takes_value(true),
|
.takes_value(true),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new("iplist")
|
||||||
|
.long("ip-addr")
|
||||||
|
.help("Inline list of IP addresses to impersonate, comma-separated")
|
||||||
|
.takes_value(true),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("verbosity")
|
Arg::new("verbosity")
|
||||||
.short('v')
|
.short('v')
|
||||||
|
@ -173,7 +178,7 @@ fn main() {
|
||||||
};
|
};
|
||||||
/* Parse ip address file specified */
|
/* Parse ip address file specified */
|
||||||
/* FIXME: .and_then(|path| File::open(path).map(|file| )).unwrap_or_default() ? */
|
/* FIXME: .and_then(|path| File::open(path).map(|file| )).unwrap_or_default() ? */
|
||||||
let ip_list = if let Some(ref path) = args.value_of("ip") {
|
let mut ip_list = if let Some(ref path) = args.value_of("ipfile") {
|
||||||
if let Ok(file) = File::open(path) {
|
if let Ok(file) = File::open(path) {
|
||||||
info!("parsing ip address file: {}", &path);
|
info!("parsing ip address file: {}", &path);
|
||||||
file.extract_ip_addresses_only(None)
|
file.extract_ip_addresses_only(None)
|
||||||
|
@ -183,9 +188,17 @@ fn main() {
|
||||||
} else {
|
} else {
|
||||||
HashSet::new()
|
HashSet::new()
|
||||||
};
|
};
|
||||||
|
if let Some(ip_inline_list) = args.value_of("iplist") {
|
||||||
|
ip_list.extend(ip_inline_list.extract_ip_addresses_only(None));
|
||||||
|
}
|
||||||
let ip_addresses = if !ip_list.is_empty() {
|
let ip_addresses = if !ip_list.is_empty() {
|
||||||
|
for ip in &ip_list {
|
||||||
|
info!("binding........{}", ip);
|
||||||
|
}
|
||||||
Some(&ip_list)
|
Some(&ip_list)
|
||||||
} else {
|
} else {
|
||||||
|
info!("binding........0.0.0.0");
|
||||||
|
info!("binding........::");
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let mut masscanned = Masscanned {
|
let mut masscanned = Masscanned {
|
||||||
|
|
|
@ -134,6 +134,45 @@ impl IpAddrParser for File {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Parse IP addresses from a comma-separated list in a string */
|
||||||
|
impl IpAddrParser for &str {
|
||||||
|
fn extract_ip_addresses_with_count(
|
||||||
|
self,
|
||||||
|
_blacklist: Option<HashSet<IpAddr>>,
|
||||||
|
) -> HashMap<IpAddr, u32> {
|
||||||
|
panic!("not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn extract_ip_addresses_only(self, blacklist: Option<HashSet<IpAddr>>) -> HashSet<IpAddr> {
|
||||||
|
let mut ip_addresses = HashSet::new();
|
||||||
|
for line in self.split(",") {
|
||||||
|
/* Should never occur */
|
||||||
|
if line.is_empty() {
|
||||||
|
warn!("cannot parse line: {}", line);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let ip: IpAddr;
|
||||||
|
if let Ok(val) = line.parse::<Ipv4Addr>() {
|
||||||
|
ip = IpAddr::V4(val);
|
||||||
|
} else if let Ok(val) = line.parse::<Ipv6Addr>() {
|
||||||
|
ip = IpAddr::V6(val);
|
||||||
|
} else {
|
||||||
|
warn!(
|
||||||
|
"cannot parse IP address from line: {}", line
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if let Some(ref b) = blacklist {
|
||||||
|
if b.contains(&ip) {
|
||||||
|
info!("[blacklist] ignoring {}", &ip);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ip_addresses.insert(ip);
|
||||||
|
}
|
||||||
|
ip_addresses
|
||||||
|
}
|
||||||
|
}
|
||||||
/* Get the IP address of source and dest. from an IP packet.
|
/* Get the IP address of source and dest. from an IP packet.
|
||||||
* works with both IPv4 and IPv6 packets/addresses */
|
* works with both IPv4 and IPv6 packets/addresses */
|
||||||
fn extract_ip(pkt: Packet) -> Option<(IpAddr, IpAddr)> {
|
fn extract_ip(pkt: Packet) -> Option<(IpAddr, IpAddr)> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue