Skip to content

Commit 9080614

Browse files
feat: add port scanner command to main application
1 parent 2cbabb3 commit 9080614

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

src/commands/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
pub mod help;
1+
pub mod help;
2+
pub mod port_scanner;

src/commands/port_scanner.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use std::io;
2+
use std::net::TcpStream;
3+
use std::time::Duration;
4+
5+
pub fn launch_port_scanner() {
6+
let mut target_ip = String::new();
7+
let mut target_port = String::new();
8+
9+
println!("Welcome to the port scanner!");
10+
11+
println!("enter the target IP address: ");
12+
io::stdin().read_line(&mut target_ip).unwrap();
13+
14+
println!("enter the target port to scan: ");
15+
io::stdin().read_line(&mut target_port).unwrap();
16+
17+
let target = format!("{}:{}", target_ip.trim(), target_port.trim());
18+
19+
println!("scanning {} on port {}", target_ip, target_port);
20+
if (TcpStream::connect(&target)).is_ok() {
21+
println!("successfully connected to {}", target);
22+
} else {
23+
println!("failed to connect to {}", target);
24+
}
25+
}

src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ mod commands;
22

33
use std::{fs, io};
44
use crate::commands::help::show_help;
5+
use crate::commands::port_scanner::launch_port_scanner;
56

67
fn main() {
78
let mut input = String::new();
@@ -19,6 +20,7 @@ fn main() {
1920
"test" => println!("this is test command"),
2021
"quit" => break,
2122
"help" => show_help(),
23+
"ipscanner" => launch_port_scanner(),
2224
_ => println!("Uknown input"),
2325
}
2426
}

0 commit comments

Comments
 (0)