#!/usr/bin/perl # # AGI Script that prompts the user for an ip address, scans the ip, and reports back to the user. # # Requires the Cepstral TTS engine, Asterisk::AGI, and Nmap::Parser perl modules # # Written by: Black Rathchet (blackratchet@blackratchet.org) # # use Asterisk::AGI; use Nmap::Parser; use File::Basename; use Digest::MD5 qw(md5_hex); sub speak(){ $text = $_[0]; my $hash = md5_hex($text); my $ttsdir = "/var/lib/asterisk/sounds/tts"; my $cepoptions = "-p audio/sampling-rate=8000,audio/channels=1"; my $wavefile = "$ttsdir/tts-$hash.wav"; unless (-f $wavefile) { open(fileOUT, ">/var/lib/asterisk/sounds/tts/say-text-$hash.txt"); print fileOUT "$text"; close(fileOUT); my $execf="/opt/swift/bin/swift -f $ttsdir/say-text-$hash.txt -o $wavefile $cepoptions"; system($execf); unlink("$ttsdir/say-text-$hash.txt"); } $filename = 'tts/'.basename('tts/'.basename($wavefile,".wav")); $AGI->stream_file($filename); unlink("$wavefile"); } $AGI = new Asterisk::AGI; my %input = $AGI->ReadParse(); my $finished = 0; &speak("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}/) { &speak("Invalid Address: $ipaddr"); exit 0; } &speak("Oh ratchet... you know how to push my buttons..."); &speak("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) &speak("Host Found with " . $host_obj->tcp_ports_count() . " ports open"); my @ports = $host_obj->tcp_ports; #all ports foreach $port (@ports){ if($host_obj->tcp_port_state($port) ne 'closed'){ &speak($host_obj->tcp_service_name($port). " on port" . $port); } } &speak("Scan complete... Thank you..."); exit; } $AGI->exec('Festival', '"No host found"'); exit;