socket problemo

Posted on 2003-03-31
Medium Priority
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 = "";
$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";

sub try
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";

how can i multi thread it so that it does ...say...20 port scans at once all on different ports.
thanks in advance
Question by:siliconite
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

Expert Comment

ID: 8237614
Use fork(); if u prefer

Is this the full code?????

Author Comment

ID: 8238039
yea it is the full code could you tell me how to use fork

Accepted Solution

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.


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);

Expert Comment

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

Expert Comment

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

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