Important alert: (current site time 7/15/2013 9:17:45 PM EDT)
 

VB icon

lame subnet scan

Email
Submitted on: 10/3/2005 2:16:10 PM
By: enezneb 
Level: Beginner
User Rating: Unrated
Compatibility: 5.0 (all versions), Active Perl specific, 4.0 (all versions), 3.0 (all versions), Pre 3.0
Views: 7591
(About the author)
 
     Scans a whole xxx.xxx subnet for an open door. I did build it for my needs only, i could improve its quality but not necessary at all..it does what i want somehow!
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
=**************************************
= Name: lame subnet scan
= Description:Scans a whole xxx.xxx subnet for an open door. 
I did build it for my needs only, i could improve its quality but not necessary at all..it does what i want somehow!
= By: enezneb
=
= Inputs:subnet 
port
=
= Returns:log.file ( contains hosts that has the scanned port opened)
ip.list ( file which receives the lame subnet ip generator)
=
= Assumes:Problems: the code was supposed to print "*" for hosts with opendoor, and "." for not open at the moment the host is checked, but the code only does it when the scan process is done. somebody knows why ? email me !
clean $logfile and $targetfile for future use.. didnt set something to clean them up.
=
=This code is copyrighted and has= limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=666&lngWId=6=for details.=**************************************

#!/usr/bin/perl# i have created this for my needs so... =)
# thanks for google.com
# created by : enezneb
# ---scan a whole xxx.xxx subnet for an open port----
# dont know why the hell the prints statements doesnt print on real time.
# should print "*" for open and "." for not open(at the moment they are checked)
# but it only prints after doing the entire scan process.
# if u know why send email: benzene at globo dot com
#
# PS: after using the scan, clean ip.list and log.file
# its a lame code, i could manage to clean them up, or set them like an argument
# but i;m lazy kakakaka and i only use xxx.xxx subnets(my needs),
# change to your needs if u want
#
# change $logfile and $targetfile ( path to)
use Socket;
$proto = getprotobyname(shift || 'tcp');
print "Subnet to scan:(ex.: 200.1)";
$subnet=<STDIN>;
chop($subnet);
print "Port to scan:";
$port=<STDIN>;
chop($port);
$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";
$logfile = '/pub/log.file';
open(LOGFILE, ">>$logfile") || die "Could not open log file\n";
open(IPLIST,"<$targetfile") || die "Could not open file for ip list reading\n";
 
 foreach $line (<IPLIST>){
 chomp($line);
 $iaddr = inet_aton($line);
 $paddr = sockaddr_in($port, $iaddr);
 socket(SOCKET, PF_INET, SOCK_STREAM, $proto) || die "Could not create socket\n";
 $sock = connect(SOCKET,$paddr) || next;
 if($sock)
 {
print "*";
print LOGFILE "$line\n";
 }else{
 print ".";
 }
}
close(LOGFILE);
close(IPLIST);


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.