Skip to content

Commit f7e10cf

Browse files
committed
feat: add hostname next to ip in ports tab
1 parent 49abdeb commit f7e10cf

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/components/ports.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const SPINNER_SYMBOLS: [&str; 6] = ["⠷", "⠯", "⠟", "⠻", "⠽", "⠾"];
3535
pub struct ScannedIpPorts {
3636
pub ip: String,
3737
state: PortsScanState,
38+
hostname: String,
3839
pub ports: Vec<u16>,
3940
}
4041

@@ -78,12 +79,14 @@ impl Ports {
7879

7980
fn process_ip(&mut self, ip: &str) {
8081
let ipv4: Ipv4Addr = ip.parse().unwrap();
82+
let hostname = lookup_addr(&ipv4.into()).unwrap_or_default();
8183

8284
if let Some(n) = self.ip_ports.iter_mut().find(|item| item.ip == ip) {
8385
n.ip = ip.to_string();
8486
} else {
8587
self.ip_ports.push(ScannedIpPorts {
8688
ip: ip.to_string(),
89+
hostname,
8790
state: PortsScanState::Waiting,
8891
ports: Vec::new(),
8992
});
@@ -201,8 +204,16 @@ impl Ports {
201204
for ip in &self.ip_ports {
202205
let mut lines = Vec::new();
203206

204-
let ip_line = Line::from(vec!["IP: ".yellow(), ip.ip.clone().cyan()]);
205-
lines.push(ip_line);
207+
let mut ip_line_vec = vec![
208+
"IP: ".yellow(),
209+
ip.ip.clone().blue(),
210+
];
211+
if !ip.hostname.is_empty() {
212+
ip_line_vec.push(" (".into());
213+
ip_line_vec.push(ip.hostname.clone().cyan());
214+
ip_line_vec.push(")".into());
215+
}
216+
lines.push(Line::from(ip_line_vec));
206217

207218
let mut ports_spans = vec!["PORTS: ".yellow()];
208219
if ip.state == PortsScanState::Waiting {

0 commit comments

Comments
 (0)