Sign in to follow this  
mesvak

PERL port scanner ez gezy

Recommended Posts

[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]

Share this post


Link to post
Share on other sites

i presh8 your effort thanks for this

Share this post


Link to post
Share on other sites

this is so lit I lost my hair  :hype: 

thanks for the post mate, hope it works :wut:

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this