зацените сканер портов для диапазона ip

Discussion in 'PHP' started by nerezus, 6 Jun 2005.

  1. nerezus

    nerezus Banned

    Joined:
    12 Aug 2004
    Messages:
    3,191
    Likes Received:
    729
    Reputations:
    266
    сканер портов для диапазона ip
    Code:
    #!/usr/bin/perl -w
     
     # PortMap by nerezus
     # The Artistic License
     # ICQ 547097
     #
     # A tool for scan ip range
     
     use strict;
     use Socket;
     
     if (@ARGV<2) {print "Usage: portmap.pl from_host(ip) to_host(ip) [portfile.txt(ports via [space])]\n";exit(0);}
     my $fremote=shift||'127.0.0.1';
     my $tremote=shift||'127.0.0.1';
     my $portfile=shift;
     my $ports;
     if ($portfile) {open (PF, $portfile); $ports=<PF>; close(PF);}
        else {$ports="21 80";}
     my @ports=split(/ /, $ports);
     my @flist=split(/\./, $fremote);
     my @tlist=split(/\./, $tremote);
     my $fip=$flist[0]*256*256*256+$flist[1]*256*256+$flist[2]*256+$flist[3];
     my $tip=$tlist[0]*256*256*256+$tlist[1]*256*256+$tlist[2]*256+$tlist[3];
     
     for (my $i=$fip; $i<=$tip; $i++) {
     	my $tmp=$i;
     	my $d1=int($tmp / (256*256*256)); $tmp=$tmp-$d1*(256*256*256);
     	my $d2=int($tmp / (256*256)); $tmp=$tmp-$d2*(256*256);
     	my $d3=int($tmp / 256); $tmp=$tmp-$d3*256;
     	my $d4=$tmp;
     	my $ip="$d1.$d2.$d3.$d4";
     	my $host=gethostbyname($ip);
     	foreach my $port (@ports){
     			my $dest=sockaddr_in($port, $host);
     			socket (S, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
     			if (connect(S, $dest)) {print "[".scalar(localtime)."] $ip:$port OK\n";}
     #			   else {print "[".scalar(localtime)."] $ip:$port ERR\n";}
     			close S;
     			}
     }
     
  2. m0nzt3r

    m0nzt3r моня

    Joined:
    22 Jun 2004
    Messages:
    2,096
    Likes Received:
    673
    Reputations:
    591
    наверно хорооший если это ты написал ))) жаль что не смогу щас заценить(я из клуба захожу))
     
  3. Algol

    Algol New Member

    Joined:
    29 May 2002
    Messages:
    1,759
    Likes Received:
    4
    Reputations:
    0
    А в мультипоточном режиме слабо ?
    :)
     
  4. nerezus

    nerezus Banned

    Joined:
    12 Aug 2004
    Messages:
    3,191
    Likes Received:
    729
    Reputations:
    266
    после 17(экзамен у меня последний)
     
  5. CyberHack

    CyberHack New Member

    Joined:
    20 May 2005
    Messages:
    16
    Likes Received:
    0
    Reputations:
    0
    ja v etom dele noob tak6to nesmejtes.
    ego nado zakinut v php ili na delphi ili c++ pisat?
    v kakom on farmate dolzen bit?
     
    #5 CyberHack, 8 Jun 2005
    Last edited: 8 Jun 2005
  6. k00p3r

    k00p3r Banned

    Joined:
    31 May 2005
    Messages:
    430
    Likes Received:
    8
    Reputations:
    2
    v Perl formate
     
  7. nerezus

    nerezus Banned

    Joined:
    12 Aug 2004
    Messages:
    3,191
    Likes Received:
    729
    Reputations:
    266
    aga, iminna tak
    pasledn'uu versjyu perla mojna skachat' na activestate.com
     
  8. m0nzt3r

    m0nzt3r моня

    Joined:
    22 Jun 2004
    Messages:
    2,096
    Likes Received:
    673
    Reputations:
    591
    попробовал...неплохой вроде бы