#!/usr/bin/perl # # AGI Script that prompts the user for an ip address, scans the ip, and reports back to the user. # # Requires the Festival TTS Engine, Asterisk::AGI, and Nmap::Parser perl modules # # Written by: Black Ratchet (blackratchet@blackratchet.org) # # use Asterisk::AGI; use Nmap::Parser; $AGI = new Asterisk::AGI; my %input = $AGI->ReadParse(); my $finished = 0; $AGI->exec('Festival', '"Enter the eye-p address you wish to scan."'); my $ipaddr = ''; my $x = 0; while (!$finished) { my $input = chr($AGI->wait_for_digit('5000')); if ($input =~ /^[0-9\*\#]$/) { if ($input =~ /^[\*\#]$/) { $x++; if ($x > 3) { $finished = 1; } else { $ipaddr .= '.'; } } else { $ipaddr .= $input; } } else { #must have timed out $finished = 1; } if ( length($ipaddr) > 14) { $finished = 1; } } if ($ipaddr !~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/) { $AGI->exec('Festival', "\"Invalid Address: $ipaddr\""); exit 0; } $AGI->exec('Festival', '"Please wait"'); my $np = new Nmap::Parser; $nmap_exe = '/usr/bin/nmap'; $np->register_host_callback(\&host_handler); $np->parsescan($nmap_exe,'-sT -p1-1023', $ipaddr); sub host_handler { my $host_obj = shift; #an instance of Nmap::Parser::Host (for current) $AGI->exec('Festival', '"Host Found with"'); $AGI->exec('Festival', $host_obj->tcp_ports_count()); $AGI->exec('Festival', '"ports open"'); my @ports = $host_obj->tcp_ports; #all ports foreach $port (@ports){ if($host_obj->tcp_port_state($port) ne 'closed'){ #$string = $host_obj->tcp_service_name($port) . " on port " . $port; $AGI->exec('Festival', $host_obj->tcp_service_name($port)); $AGI->exec('Festival', '"on port"'); $AGI->exec('Festival', $port); } } exit; } $AGI->exec('Festival', '"No host found"'); exit;