diff options
author | Till Kamppeter <tkamppeter@mandriva.com> | 2002-08-01 23:18:54 +0000 |
---|---|---|
committer | Till Kamppeter <tkamppeter@mandriva.com> | 2002-08-01 23:18:54 +0000 |
commit | 4debb6278e650860bc8223534e5f6c4592f1f5a2 (patch) | |
tree | ee3b62f887c0c6b67dadeef9285971c8806a90c5 /perl-install | |
parent | 01a4038362a30c909ac8115b897d77bc2e705e44 (diff) | |
download | drakx-backup-do-not-use-4debb6278e650860bc8223534e5f6c4592f1f5a2.tar drakx-backup-do-not-use-4debb6278e650860bc8223534e5f6c4592f1f5a2.tar.gz drakx-backup-do-not-use-4debb6278e650860bc8223534e5f6c4592f1f5a2.tar.bz2 drakx-backup-do-not-use-4debb6278e650860bc8223534e5f6c4592f1f5a2.tar.xz drakx-backup-do-not-use-4debb6278e650860bc8223534e5f6c4592f1f5a2.zip |
Added facility to scan network for SMB/Windows-hosted printers.
Diffstat (limited to 'perl-install')
-rw-r--r-- | perl-install/detect_devices.pm | 70 |
1 files changed, 61 insertions, 9 deletions
diff --git a/perl-install/detect_devices.pm b/perl-install/detect_devices.pm index 4514d5f5e..dad7967b6 100644 --- a/perl-install/detect_devices.pm +++ b/perl-install/detect_devices.pm @@ -654,13 +654,41 @@ sub getSNMPModel { }; } +sub getSMBPrinterShares { + + my ($host) = @_; + + # SMB request to auto-detect shares + local *F; + open F, "export LC_ALL=\"C\"; smbclient -N -L $host |" || return (); + my $insharelist = 0; + my @shares; + while (my $l = <F>) { + chomp $l; + if ($l =~ /^\s*Sharename\s+Type\s+Comment\s*$/i) { + $insharelist = 1; + } elsif ($l =~ /^\s*Server\s+Comment\s*$/i) { + $insharelist = 0; + } elsif (($l =~ /^\s*(\S+)\s+Printer\s*(.*)$/i) && + ($insharelist)) { + my $name = $1; + my $description = $2; + $description =~ s/^(\s*)//; + push (@shares, { name => $name, description => $description }); + } + } + close F; + + return @shares; +} + sub whatNetPrinter () { my $i; my @res; - # Scan network for printers (one of ports 9100-9199 open) + # Scan network for printers local *F; - open F, "export LC_ALL=\"C\"; nmap -p 4010,4020,4030,5503,9100-9104 `route | egrep \"^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\" | cut -f 1 -d \" \" | grep -v \"127\\.0\\.0\\.0\" | sed \"s/\\.0\$/\\.*/\"` |" || + open F, "export LC_ALL=\"C\"; nmap -p 139,4010,4020,4030,5503,9100-9104 `route | egrep \"^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\" | cut -f 1 -d \" \" | grep -v \"127\\.0\\.0\\.0\" | sed \"s/\\.0\$/\\.*/\"` |" || return @res; my $host = ""; my $ip = ""; @@ -679,18 +707,42 @@ sub whatNetPrinter () { } $port = ""; - # SNMP request to auto-detect model - $modelinfo = getSNMPModel ($ip); + undef $modelinfo; } elsif ($line =~ m/^\s*(\d+)\/\S+\s+open\s+/i) { - next if ($ip eq "") || (!defined($modelinfo)); + next if ($ip eq ""); $port = $1; - + # Now we have all info for one printer # Store this auto-detection result in the data structure - push @res, { port => "socket://$host:$port", - val => $modelinfo - }; + + # Determine the protocol by the port number + + # SMB/Windows + if ($port eq "139") { + my @shares = getSMBPrinterShares($ip); + for my $share (@shares) { + push @res, { port => "smb://$host/$share->{name}", + val => { CLASS => 'PRINTER', + MODEL => _("Unknown Model"), + MANUFACTURER => "", + DESCRIPTION => + "$share->{description}", + SERIALNUMBER => "" + } + }; + } + } else { + if (!defined($modelinfo)) { + # SNMP request to auto-detect model + $modelinfo = getSNMPModel ($ip); + } + if (defined($modelinfo)) { + push @res, { port => "socket://$host:$port", + val => $modelinfo + }; + } + } } } close F; |