File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- pub mod help;
1+ pub mod help;
2+ pub mod port_scanner;
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ mod commands;
22
33use std:: { fs, io} ;
44use crate :: commands:: help:: show_help;
5+ use crate :: commands:: port_scanner:: launch_port_scanner;
56
67fn 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 }
You can’t perform that action at this time.
0 commit comments