介绍
如果你用过网络打印机,你能很好地理解网络扫描仪是什么——网络扫描仪就是在一个网络中共享的扫描仪。具体而言它的作用就是,可以在一个扫描仪接入一个主机后,让这个主机所在的网络里的其他主机通过网络连接这个网络扫描仪而不用把这个扫描仪直接接入其他主机。这省去了很多麻烦。
从这里,我们引入几个名词:
- 扫描仪服务器:扫描仪直接连入的主机。
- 客户端主机:与扫描仪服务器处于同一网络下,能与扫描仪服务器通信的主机。
这个教程会教会你如何在Ubuntu上部署SANE服务以建立网络打印机,并让客户端顺利连接访问。
参考教程:
- https://help.ubuntu.com/community/SaneDaemonTutorial
- https://penguin-breeder.org/sane/saned/
- https://wiki.archlinux.org/title/SANE
前提环境
为了让这个教程更加易懂,先给出一个环境:
- 网络是192.168.114.0/24
- 扫描仪服务器(扫描仪直接接入的主机)的IP地址是192.168.114.1
- 扫描仪服务器系统是Ubuntu 22.04 LTS
服务器配置
确保扫描仪服务器可以连接扫描仪
请确保你的扫描仪服务器可以直接连接这个扫描仪,这可能需要安装这个扫描仪对应的一些驱动程序。
可以通过以下命令查询能连接的扫描仪:
scanimage -L如果成功会打印如下类似的信息:
device `brother4:bus1;dev5' is a Brother MFC-7480D USB scanner
共享你的扫描仪
打开这个配置文件:
vim /etc/sane.d/saned.conf找到如下所示的地方,这里配置的就是哪些客户端主机可以访问这个扫描仪服务器:
## Access list
# A list of host names, IP addresses or IP subnets (CIDR notation) that
# are permitted to use local SANE devices. IPv6 addresses must be enclosed
# in brackets, and should always be specified in their compressed form.
#
# The hostname matching is not case-sensitive.
#scan-client.somedomain.firm
#192.168.0.1
#192.168.0.1/29
#[2001:db8:185e::42:12]
#[2001:db8:185e::42:12]/64
因此我们做如下改动:
## Access list
# A list of host names, IP addresses or IP subnets (CIDR notation) that
# are permitted to use local SANE devices. IPv6 addresses must be enclosed
# in brackets, and should always be specified in their compressed form.
#
# The hostname matching is not case-sensitive.
#scan-client.somedomain.firm
#192.168.0.1
#192.168.0.1/29
#[2001:db8:185e::42:12]
#[2001:db8:185e::42:12]/64
+ 192.168.114.0/24启动SANE服务
输入如下命令:
systemctl start saned.socket到这里,你的扫描仪服务器配置就已经完成了。
客户端配置
Linux
我这里客户端主机的系统是Ubuntu 22.04 LTS。
配置自动扫描
首先打开这个配置文件:
vim /etc/sane.d/net.conf找到如下所示的地方,这个地方填写的主机就是让你的客户端自动扫描有没有网络扫描仪的主机:
## saned hosts
# Each line names a host to attach to.
# If you list "localhost" then your backends can be accessed either
# directly or through the net backend. Going through the net backend
# may be necessary to access devices that need special privileges.
所以需要做如下改动:
## saned hosts
# Each line names a host to attach to.
# If you list "localhost" then your backends can be accessed either
# directly or through the net backend. Going through the net backend
# may be necessary to access devices that need special privileges.
+ 192.168.114.1现在在你的客户端主机上查询能连接的扫描仪:
scanimage -L若配置成功且一切正常,将会显示如下类似的信息:
device `net:192.168.114.1:brother4:bus1;dev5' is a Brother MFC-7480D USB scanner
测试
利用scanimage进行一次测试:
scanimage --format=png > output.png若需要指定扫描仪,可以添加-d参数:
scanimage -d "net:192.168.114.1:brother4:bus1;dev5" --format=png > output.png其他工具
scanimage是一个纯命令行的程序,无法实时预览扫描结果,并不是很好用,这里有其他的一些SANE前端可供使用:
Windows
你不能直接使用Windows自带的扫描工具,因为它采用的扫描协议与SANE不同。但是你可以试着用其他的一些工具,虽然都不好用。等我有时间了想办法参悟一下SANE,试着用C#写一个。