?
Solved

socket problemo

Posted on 2003-03-31
5
Medium Priority
?
218 Views
Last Modified: 2010-03-05
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
Comment
Question by:siliconite
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 3

Expert Comment

by:prady_21
ID: 8237614
Use fork(); if u prefer

Is this the full code?????
0
 

Author Comment

by:siliconite
ID: 8238039
yea it is the full code could you tell me how to use fork
0
 
LVL 3

Accepted Solution

by:
prady_21 earned 225 total points
ID: 8242340
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
 
LVL 3

Expert Comment

by:prady_21
ID: 8242344
i am sorry, the second part is the sending side, which i have termed as receiving side.
0
 

Expert Comment

by:stiletto2003
ID: 8244077
cheers mate thnaks so much for youre time.
here r the points
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question