Skip to content

Instantly share code, notes, and snippets.

@tacitochaves
Created May 23, 2014 17:00
Show Gist options
  • Save tacitochaves/23dec9230ecb08d84bbc to your computer and use it in GitHub Desktop.
Save tacitochaves/23dec9230ecb08d84bbc to your computer and use it in GitHub Desktop.
Check port open with IP
#!/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