How to implement a port scanner using some scripting language?

5.42K viewsProgramminghacking nodejs port programming scanner
0

How to implement a port scanner using some scripting language?

Answered question
0

Below is a port scanner in PERL:-

Below is a small perl script to achieve the same
 #!/usr/bin/perl
 use IO::Socket;
 $port = 1;
$ip   = "192.168";  // should be the IP address prefix of the IPs in your  network or localhost
$sub1 = 0;
$sub2 = 0;
$limit = 255;
 $output = "/home/L098867/Desktop/OpenPorts.txt"; // output to be redirected to this txt file
 open (LIST, " >>$output");
 while($sub1 <= $limit){
     while($sub2 <= $limit){
// scan ports from 0 until 65535
        while ($port <= 65535){
             $fip = $ip.".$sub1".".$sub2";
     $sock = new IO::Socket::INET (PeerAddr => $fip,
             PeerPort => $port,
             Proto => 'tcp');
     if ($sock){
         close $sock;
         print "$fip : " + "$port -open\n";
         print LIST "$fip : " + "$port -open\n";
    }
     else{
         print "$fip : " + "$port -closed\n";
    }
             $port = $port + 1;
            print "$fip\n\n";
        }
         $sub2 = $sub2 + 1;
        $port = 0;
        print "\n\n";
    }
     $sub1 = $sub1 + 1;
    $port = 0;
    print "\n\n";
}
 close(LIST);

Answered question
You are viewing 1 out of 2 answers, click here to view all answers.
Write your answer.

Categories