mesvak 359 [hide] #!/usr/bin/perl print "################################################################" print "# pERL port scanner #" print "# [email protected] #" print "###############################################################" use strict; use warnings; use IO::Socket::INET; #Auto-flush. $| = 1; #Get host. my $host = $ARGV[0]; #Parent thread has no parent. my $parent = 0; #We need a place to store child PIDs. my @children = (); #Port scan host. print "Scanning $host...\n"; my $port; FORK: for ($port=1; $port<=65535; $port++) { #Fork. my $oldpid = $$; my $pid = fork; #If fork failed... if (not defined $pid) { #If resource is not available... if ($! =~ /Resource temporarily unavailable/) { #Reap children. &DoReap; #Retry this port. $port --; } else { #Otherwise, show the error. die "Can't fork: $!\n"; } } elsif ($pid == 0) { #This is the child. Save parent. $parent = $oldpid; #Clearup kids table. @children = (); #We don't want this thread to fork any more. last FORK; } else { #This is the parent. Store child pid to wait on it later. push @children, $pid; } } #If this is a child (i.e. it has a parent)... if ($parent) { #Attempt to connect to $host on $port. my $socket; my $success = eval { $socket = IO::Socket::INET->new( PeerAddr => $host, PeerPort => $port, Proto => 'tcp' ) }; #If the port was opened, say it was and close it. if ($success) { print "Port $port: Open\n"; shutdown($socket, 2); } #Exit. exit 0; } else { #If we're not the kid, we're the parent. Do a reap. rape can be done as well XD. &DoReap; } #This sub is the reaper. sub DoReap { while (my $child = shift @children) { waitpid $child, 0; } } [/hide] Quote Share this post Link to post Share on other sites
tutyug 3 this is so lit I lost my hair :hype: thanks for the post mate, hope it works :wut: Quote Share this post Link to post Share on other sites