Gossamer Forum
Home : General : Perl Programming :

When executed freezes .. why?

Quote Reply
When executed freezes .. why?
Here is my code :
PS: using google.com for coding perl, dont blaim me for lame mistakes, thanks hehe.
proposes: scan subnet for open door, no hacking. promise.
#!/usr/bin/perl

use Socket;
$proto = getprotobyname(shift || 'tcp');

print "Subnet to scanex.: 200.1)";
$subnet=<STDIN>;
chop($subnet);

print "Port to scan:";
$port=<STDIN>;
chop($port);


# set file for generating the ip list
$targetfile = '/pub/ip.list';
open(FILE,">>$targetfile") || die "Could not get file\n";

for($i=0;$i<=255;$i++){
for($j=1;$j<=255;$j++){
print FILE "$subnet.$i.$j\n";

}

}
close(FILE);
print "IP List generated for subnet: $subnet at $targetfile\n";
# WHEN CODE EXECUTED, IT FREEZES HERE. AFTER PRINTING LINE ABOVE
# ip.list generated.

# set file for logging

$logfile = '/pub/log.file';
open(LOGFILE, ">>$logfile") || die "Could not open log file\n";

# logfile will be closed after scan process is done


# open file for reading ip

open(IPLIST,"<$targetfile") || die "Could not open file for ip list reading\n";

print "Start scanning IP list on port: $port";

while(<IPLIST>){

$host = $_; # host will be each line of the targetfile
chomp; # Is THIS right? OR SHOULD I USE CHOP($HOST) ?
$iaddr = inet_aton($host);
$paddr = sockaddr_in($port,$iaddr);

socket(SOCKET, PF_INET, SOCK_STREAM, $proto) || die "Could not create socket\n";
$sock = connect(SOCKET,$paddr) || die "could not connect";

print "*" if ($sock) || print "."; # . if not open * if port is open
# dont know if line above works, but u guys got what i meant to do

print LOGFILE "$host\n" if ($sock);

}
close(LOGFILE);
close(IPLIST);

print "Scan completed read $logfile for results";
print "After using the scan, clean ip.list and log.file";

So my issues:

1) when the given ip($host = $_ does not exist...
how can i manage it to jump to next try?
for now im breaking it with "die".
i tried: $sock = connect(......)
if($sock) {
do stuff
}
else{}
} # end of while instruction block
i thought it would jump to next try, but its not working


Well. i need help to understand what is going on. Why the hell the execution freezes...
xxx.xxx.0.1 to xxx.xxx.255.255 is huge... the open() handles it ?
dont know whats is going wrong in this code.
PS2: the $targetfile is in append mode while generating iplist,im using an empty file ( echo > file ), so i can append already.

thanks dudes

Last edited by:

fferrandini: Sep 30, 2005, 4:32 PM
Quote Reply
Re: [fferrandini] When executed freezes .. why? In reply to
Mmm.. bit weary about why you'd want to scan peoples ports? Pirate
Quote Reply
Re: [Andy] When executed freezes .. why? In reply to
education, learning needs... reading and learning handling sockets in differents programming languages...

can u help or not ? Unsure
Quote Reply
Re: [fferrandini] When executed freezes .. why? In reply to
Where does it get to before it freezes?