-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathscanner.pl
53 lines (41 loc) · 1.05 KB
/
scanner.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/perl
# TCP Port scanner
use IO::Socket;
# flush the print buffer immediately
$| = 1;
# Take input from user - hostname, start port , end port
print "Enter Target/hostname : ";
# Need to chop off the newline character from the input
chop ($target = <stdin>);
print "Start Port : ";
chop ($start_port = <stdin>);
&check_port($start_port);
print "End Port : ";
chop ($end_port = <stdin>);
&check_port($end_port);
# start the scanning loop
foreach ($port = $start_port ; $port <= $end_port ; $port++)
{
#\r will refresh the line
print "\rScanning port $port";
#Connect to port number
$socket = IO::Socket::INET->new(PeerAddr => $target , PeerPort => $port , Proto => 'tcp' , Timeout => 1);
#Check connection
if( $socket )
{
print "\r = Port $port is open.\n" ;
}
else
{
#Port is closed, nothing to print
}
}
print "\n\nFinished Scanning $target\n";
exit (0);
sub check_port {
my $port = shift;
if ($port =~ /\D+/ or $port > 65535 or $port < 0) {
print "Please check the format of port: $port\n";
exit 1;
}
}