Created
May 23, 2014 17:00
-
-
Save tacitochaves/23dec9230ecb08d84bbc to your computer and use it in GitHub Desktop.
Check port open with IP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use 5.12.0; | |
print "**********************************\n"; | |
print "* PORT SCAN - São Luís TECNOLOGY *\n"; | |
print "**********************************\n"; | |
print "\n Digite o IP Alvo........:"; | |
chomp(my $ip=<STDIN>); | |
print " Digite a Porta Inicial..:"; | |
chomp(my $porta_inicial=<STDIN>); | |
print " Digite a Porta Final....:"; | |
chomp(my $porta_final=<STDIN>); | |
if ($porta_inicial >= $porta_final) { | |
print "A porta inicial deve ser menor que a porta final. \n"; | |
exit(1); | |
} | |
my $porta_ini_valida="1"; | |
my $porta_fin_valida="1"; | |
if ($porta_inicial < "1" or $porta_inicial > "65536") { | |
$porta_ini_valida ="0"; | |
} | |
if ($porta_final < "1" or $porta_final > "65536"){ | |
$porta_fin_valida = "0"; | |
} | |
if ( $porta_ini_valida == "0" or $porta_fin_valida =="0" ) { | |
print "Porta Inválida \n"; | |
exit(1); | |
} | |
use IO::Socket; | |
while ( $porta_inicial <= $porta_final ) { | |
my $socket = new IO::Socket::INET ( | |
PeerAddr => "$ip", | |
PeerPort => "$porta_inicial", | |
Proto => "tcp", | |
Timeout => "1", | |
); | |
print "Porta $porta_inicial: "; | |
if ( $socket ) { | |
print "Aberta\n"; | |
} else { | |
print "Fechada\n"; | |
} | |
$porta_inicial++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment