Leser: 2
8 Einträge, 1 Seite |
@OPorts[$a] = $i; $a++;
&scanstart($host, $startport, $stopport);
1
2
3
4
5
6
if (&socket($host, $i) eq "True") {
print "\t* Port $i; Open!\n";
$OPorts[$a] = $i;
$a++;
}
else { print "\t* Port $i; Closed!\n" }
1
2
3
4
5
6
7
8
9
10
11
12
sub socket {
my($host, $cport) = @_;
my $socket = IO::Socket::INET->new (
PeerAddr => $host,
PeerPort => $cport,
Proto => "tcp",
Timeout => 1,
Type => SOCK_STREAM
);
return $socket;
}
return $socket ? "True" : "False";
1
2
3
4
5
if ( &socket($host, $i) ) {
print "\t* Port $i; Open!\n";
$OPorts[$a] = $i;
$a++;
} else { print "\t* Port $i; Closed!\n" }
) || { $bool = "False" };
1
2
3
4
5
6
) || ( $bool = "False" )
# oder so etwas...
my $socket = IO::Socket::INET->new (
# [ ... ]
);
my $bool = $socket ? "True" : "False";
foreach $pp (@OPorts) { print "$pp, " }
print join ',' => @OPorts
1
2
3
4
5
6
7
8
foreach my $port ( $startport .. $stopport ) {
if # [ ... ] port offen
# [ ... ]
push @OPorts, $port;
else { # port geschlossen
# [ ... ]
}
}
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
54
55
56
57
58
use strict;
use warnings;
use IO::Socket::INET;
my $sock = IO::Socket::INET->async_new(
PeerAddr => 'board.perl-community.de',
PeerPort => 80,
Proto => "tcp",
Timeout => 1,
Type => SOCK_STREAM,
AsyncTimeout => 1000
);
package IO::Socket;
use strict;
use warnings;
use threads;
use threads::shared;
my $can_connect = 0;
my $is_shared = 0;
sub async_new_cb {
my ($self, $sockref, %args) = @_;
${$sockref} = $self->new(%args);
$can_connect = 1;
cond_signal($can_connect);
}
sub async_new {
my ($self, %args) = @_;
$args{AsyncTimeout} ||= 1000;
my $sockobj = undef;
my $thread = threads->create('async_new_cb', $self, \$sockobj, %args);
unless($is_shared) {
share($can_connect);
$is_shared = 1;
}
$can_connect = 0;
lock($can_connect);
until($can_connect) {
last if !cond_timedwait($can_connect, time() + $args{AsyncTimeout});
}
return $can_connect ? $sockobj : undef;
}
1;
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
#Portscanner
use IO::Socket;
$info = "\t* Simple Portscanner by GloBoX\n\n";
sub start {
if ($#ARGV != 2) { die "Use: $0 host startport stopport\n" }
else {
$host = $ARGV[0];
$startport = $ARGV[1];
$stopport = $ARGV[2];
if ($startport >= $stopport) { die "Use: $0 host startport stopport\n" }
print $info;
&scanstart();
}
}
sub socket {
$cport = $_[0];
$bool = "True";
$socket = IO::Socket::INET->new (
PeerAddr => $host,
PeerPort => $cport,
Proto => "tcp",
Timeout => 1,
Type => SOCK_STREAM
) || { $bool = "False" };
return($bool);
}
sub scanstart {
my $a = -1;
print "\t** Scanning **\n";
for ($i = $startport; $i <= $stopport; $i++) {
if (&socket($i) eq "True") {
print "\t* Port $i; Open!\n";
@OPorts[$a] = $i; $a++;
}
else { print "\t* Port $i; Closed!\n" }
}
print "\n** Open Ports: ";
foreach $pp (@OPorts) { print "$pp, " }
}
&start();
Quote..., d.h. Forking bzw. Threading ist dein Freund.
8 Einträge, 1 Seite |