Nmap, tty and Perl
Shlomi Fish
shlomif at iglu.org.il
Thu Jun 25 12:30:29 IDT 2009
Hi Noam!
A few comments on your Perl code.
On Thursday 25 June 2009 10:59:47 Noam Rathaus wrote:
> Hi,
>
> I am trying to get nmap to be a bit more "friendly" by wrapping it
> inside a perl script that will cause it to spit out a status by
> "sending it a character":
> ==
> #!/usr/bin/perl
> use IPC::Open3;
> use POSIX ":sys_wait_h";
> use FileHandle;
>
1. You should add "use strict;" and "use warnings;". They prevent many common
errors.
2. The FileHandle module was largely superseded by IO::File, IO::Socket, etc.
You should use them instead.
> $| = 1;
> my $nmap = "/usr/bin/nmap";
> my @ips = ('192.168.1.*');
>
> my $cmdline = " $nmap $args -v -v -v -sT -p 1-65535 -oX - ".(join '
> ', at ips); print "cmdline: $cmdline\n";
>
Where is $args declared and defined?
Also consider using http://search.cpan.org/dist/String-ShellQuote/ .
> my ($readfh, $writefh, $errorfh) = (FileHandle->new(),
> FileHandle->new(), FileHandle->new());
>
This can be more elegantly written as map { IO::Handle->new() } (1 .. 3);
> my $pid = 0;
>
> $pid = open3($writefh, $readfh, $errorfh, $cmdline) || die "Can't open
> pipe to $cmdline: $!\n";
>
> while(<$readfh>) {
> print $_;
> print $writefh "A";
> }
>
Perhaps read one character at a time here? (Or set $/ ?)
> print STDERR "done\n";
>
> ==
>
Regards,
Shlomi Fish
> nmap will give out a progress if keyWasPressed is detected the code
> for this is found inside nmap_tty.cc which basically does:
> if ((c = tty_getchar()) >= 0) {
>
> For some reason the above code doesn't do it, is it because its not
> being sent via tty? if so is there a way to fool it?
>
> _______________________________________________
> Linux-il mailing list
> Linux-il at cs.huji.ac.il
> http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
Interview with Ben Collins-Sussman - http://xrl.us/bjn8s
God gave us two eyes and ten fingers so we will type five times as much as we
read.
More information about the Linux-il
mailing list