• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 220
  • Last Modified:

socket problemo

i have decided to make a socket probe to test myyyyyy security and i am trying to make it quiker
this is my code so-far:

#!c:\program files\active perl\bin\perl\
use IO::Socket;
#this is the connection bit and if it cannot connect to the port or the port is #closed then it makes fail equal to could not whatever.
# build TCP socket connection attempt
$host = "80.4.249.49";
$first = 1;
$second = 30;
open(DAT,">ports.dat") || die("Cannot Open File:$!");
print "hello this is a port scanner made by me myself and i\n";
try();



sub try
{
$porter=$first;
while ($porter<=$second)
{
 $fail="connected to host on";
$socket= IO::Socket::INET->new(PeerAddr => $host,
                                   PeerPort => $porter,
                                   Proto    => "tcp",
                                   Timeout  => 5)
     or $fail="could not connect to the host on port";
if ($fail eq "connected to host on")
{
print DAT "$fail $porter\n";
}

print "$fail $porter\n";
$porter++
}
}


how can i multi thread it so that it does ...say...20 port scans at once all on different ports.
thanks in advance
cheers
0
siliconite
Asked:
siliconite
  • 3
1 Solution
 
prady_21Commented:
Use fork(); if u prefer

Is this the full code?????
0
 
siliconiteAuthor Commented:
yea it is the full code could you tell me how to use fork
0
 
prady_21Commented:
Here is an example using fork. It is working properly. Make sure the parent dies before the child because i have been using wait.

This is the receiving side.

#!/usr/bin/perl

use IO::Socket;

$SIG{CHLD} = sub {wait ()};

$main_sock = new IO::Socket::INET ( LocalHost => 'www.somwhere.com',
                                    LocalPort => 1200,
                                    Listen    => 5,
                                    Proto     => 'tcp',
                                    Reuse     => 1,
                                  );
  die "Socket cannot be created. Reason: $!\n" unless ($main_sock);

  while ( $new_sock = $main_sock->accept() ) {
      $pid = fork();
      die "Cannot fork: $!" unless defined($pid);

      if ($pid == 0) {
##### Child process
         print $new_sock "i am in child\n";
         while ( defined ( $buf = <$new_sock> )) {
             print "You said this : $buf";
         }
         close ($main_sock);
         exit 0;
      }
      else {
##### Parent process
         for ( 1 .. 5 ) {
            print "i am in parent\n";
         }
         close ($main_sock);
         exit 0;
      }
   }


This is the receiving side
#!/usr/bin/perl -w
### A test program for sockets

use IO::Socket;

$sock = new IO::Socket::INET ( PeerAddr  => 'www.somewhere.com',
                               PeerPort => 80,
                               Proto     => 'tcp',
                             );
die " Could not be created : $! " unless $sock;

      print $sock "This is what i am sending you\n";
      while($line = <$sock>) {
         print "$line\n";
      }

close ($sock);
0
 
prady_21Commented:
i am sorry, the second part is the sending side, which i have termed as receiving side.
0
 
stiletto2003Commented:
cheers mate thnaks so much for youre time.
here r the points
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now