From 48f444aaf23bb5fe4758d141a87456f256be179b Mon Sep 17 00:00:00 2001 From: Till Kamppeter Date: Fri, 13 Sep 2002 17:35:40 +0000 Subject: Added timeouts to network scan with "nmap" so that scan does not take too long when there are machines running a firewall. To find running machines in the network, do not only a broadcast ping but also an "nmblookup" to also catch Windows machines which do not answer to ping. --- perl-install/printer.pm | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'perl-install') diff --git a/perl-install/printer.pm b/perl-install/printer.pm index 3276f3314..ccb42a65e 100644 --- a/perl-install/printer.pm +++ b/perl-install/printer.pm @@ -460,14 +460,23 @@ sub getIPsInLocalNetworks { close(IFCONFIG_OUT); my @addresses; - # Now ping all broadcast addresses + # Now ping all broadcast addresses and additionally "nmblookup" the + # networks (to find Windows servers which do not answer to ping) for my $bcast (@local_bcasts) { local *F; open F, ($::testing ? "" : "chroot $prefix/ ") . - "/bin/sh -c \"export LC_ALL=C; ping -w 1 -b -n $bcast | cut -f 4 -d ' ' | sed s/:// | egrep '^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+' | uniq\" |" + "/bin/sh -c \"export LC_ALL=C; ping -w 1 -b -n $bcast | cut -f 4 -d ' ' | sed s/:// | egrep '^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+' | uniq | sort\" |" or next; while () { chomp; push @addresses, $_ } close F; + if (-x "/usr/bin/nmblookup") { + open F, ($::testing ? "" : "chroot $prefix/ ") . + "/bin/sh -c \"export LC_ALL=C; nmblookup -B $bcast \\* | cut -f 1 -d ' ' | egrep '^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+' | uniq | sort\" |" + or next; + while () { chomp; + push @addresses, $_ if !(member($_,@addresses)) } + close F; + } } @addresses; @@ -500,10 +509,11 @@ sub whatNetPrinter { return () if $#hostips < 0; my $hostlist = join (" ", @hostips); - # Scan network for printers + # Scan network for printers, the timeout settings are there to avoid + # delays caused by machines blocking their ports with a firewall local *F; open F, ($::testing ? "" : "chroot $prefix/ ") . - "/bin/sh -c \"export LC_ALL=C; nmap -r -P0 -p $portlist $hostlist\" |" + "/bin/sh -c \"export LC_ALL=C; nmap -r -P0 --host_timeout 400 --initial_rtt_timeout 200 -p $portlist $hostlist\" |" or return @res; my $host = ""; my $ip = ""; -- cgit v1.2.1