配置cups
1.实现局域网内的其他主机访问centos的cups的打印机管理页面,防火墙放行cups的监听端口
2.在局域网的其他主机上访问cups的打印机管理页面添加打印机,并设置成共享
3.测试是否能打印

配置AirPrint
1.安装avahi,并开启服务

yum install avahi avahi-compat-libdns_sd

2.安装Python cups module

yum install system-config-printer-libs

3.在 /usr/share/cups/mime/下新建两个文件,airprint.types和airprint.convs
写入以下内容

echo "image/urf urf string(0,UNIRAST<00>)" > /usr/share/cups/mime/airprint.types
echo "image/urf application/pdf 100 pdftoraster" > /usr/share/cups/mime/airprint.convs

3通过脚本Python脚本完成配置,脚本地址:
http://www.voidcn.com/link?url=https://raw.github.com/tjfontaine/airprint-generate/master/airprint-generate.py
或者复制下面的Python脚本:

#!/usr/bin/env python"""
Copyright (c) 2010 Timothy J Fontaine <tjfontaine@atxconsulting.com>Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""import cups, os, optparse, re, urlparse
import os.path
from StringIO import StringIOfrom xml.dom.minidom import parseString
from xml.dom import minidomimport systry:import lxml.etree as etreefrom lxml.etree import Element, ElementTree, tostring
except:try:from xml.etree.ElementTree import Element, ElementTree, tostringetree = Noneexcept:try:from elementtree import Element, ElementTree, tostringetree = Noneexcept:raise 'Failed to find python libxml or elementtree, please install one of those or use python >= 2.5'XML_TEMPLATE = """<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes"></name>
<service><type>_ipp._tcp</type><subtype>_universal._sub._ipp._tcp</subtype><port>631</port><txt-record>txtvers=1</txt-record><txt-record>qtotal=1</txt-record><txt-record>Transparent=T</txt-record><txt-record>URF=none</txt-record>
</service>
</service-group>"""#TODO XXX FIXME
#<txt-record>ty=AirPrint Ricoh Aficio MP 6000</txt-record>
#<txt-record>Binary=T</txt-record>
#<txt-record>Duplex=T</txt-record>
#<txt-record>Copies=T</txt-record>DOCUMENT_TYPES = {# These content-types will be at the front of the list'application/pdf': True,'application/postscript': True,'application/vnd.cups-raster': True,'application/octet-stream': True,'image/urf': True,'image/png': True,'image/tiff': True,'image/png': True,'image/jpeg': True,'image/gif': True,'text/plain': True,'text/html': True,# These content-types will never be reported'image/x-xwindowdump': False,'image/x-xpixmap': False,'image/x-xbitmap': False,'image/x-sun-raster': False,'image/x-sgi-rgb': False,'image/x-portable-pixmap': False,'image/x-portable-graymap': False,'image/x-portable-bitmap': False,'image/x-portable-anymap': False,'application/x-shell': False,'application/x-perl': False,'application/x-csource': False,'application/x-cshell': False,
}class AirPrintGenerate(object):def __init__(self, host=None, user=None, port=None, verbose=False,directory=None, prefix='AirPrint-', adminurl=False):self.host = hostself.user = userself.port = portself.verbose = verboseself.directory = directoryself.prefix = prefixself.adminurl = adminurlif self.user:cups.setUser(self.user)def generate(self):if not self.host:conn = cups.Connection()else:if not self.port:self.port = 631conn = cups.Connection(self.host, self.port)printers = conn.getPrinters()for p, v in printers.items():if v['printer-is-shared']:attrs = conn.getPrinterAttributes(p)uri = urlparse.urlparse(v['printer-uri-supported'])tree = ElementTree()tree.parse(StringIO(XML_TEMPLATE.replace('\n', '').replace('\r', '').replace('\t', '')))name = tree.find('name')name.text = 'AirPrint %s @ %%h' % (p)service = tree.find('service')port = service.find('port')port_no = Noneif hasattr(uri, 'port'):port_no = uri.portif not port_no:port_no = self.portif not port_no:port_no = cups.getPort()port.text = '%d' % port_noif hasattr(uri, 'path'):rp = uri.pathelse:rp = uri[2]re_match = re.match(r'^//(.*):(\d+)(/.*)', rp)if re_match:rp = re_match.group(3)#Remove leading slashes from path#TODO XXX FIXME I'm worried this will match broken urlparse#results as well (for instance if they don't include a port)#the xml would be malform'd either wayrp = re.sub(r'^/+', '', rp)path = Element('txt-record')path.text = 'rp=%s' % (rp)service.append(path)desc = Element('txt-record')desc.text = 'note=%s' % (v['printer-info'])service.append(desc)product = Element('txt-record')product.text = 'product=(GPL Ghostscript)'service.append(product)state = Element('txt-record')state.text = 'printer-state=%s' % (v['printer-state'])service.append(state)ptype = Element('txt-record')ptype.text = 'printer-type=%s' % (hex(v['printer-type']))service.append(ptype)pdl = Element('txt-record')fmts = []defer = []for a in attrs['document-format-supported']:if a in DOCUMENT_TYPES:if DOCUMENT_TYPES[a]:fmts.append(a)else:defer.append(a)if 'image/urf' not in fmts:sys.stderr.write('image/urf is not in mime types, %s may not be available on ios6 (see https://github.com/tjfontaine/airprint-generate/issues/5)%s' % (p, os.linesep))fmts = ','.join(fmts+defer)dropped = []# TODO XXX FIXME all fields should be checked for 255 limitwhile len('pdl=%s' % (fmts)) >= 255:(fmts, drop) = fmts.rsplit(',', 1)dropped.append(drop)if len(dropped) and self.verbose:sys.stderr.write('%s Losing support for: %s%s' % (p, ','.join(dropped), os.linesep))pdl.text = 'pdl=%s' % (fmts)service.append(pdl)if self.adminurl:admin = Element('txt-record')admin.text = 'adminurl=%s' % (v['printer-uri-supported'])service.append(admin)fname = '%s%s.service' % (self.prefix, p)if self.directory:fname = os.path.join(self.directory, fname)f = open(fname, 'w')if etree:tree.write(f, pretty_print=True, xml_declaration=True, encoding="UTF-8")else:xmlstr = tostring(tree.getroot())doc = parseString(xmlstr)dt= minidom.getDOMImplementation('').createDocumentType('service-group', None, 'avahi-service.dtd')doc.insertBefore(dt, doc.documentElement)doc.writexml(f)f.close()if self.verbose:sys.stderr.write('Created: %s%s' % (fname, os.linesep))if __name__ == '__main__':parser = optparse.OptionParser()parser.add_option('-H', '--host', action="store", type="string",dest='hostname', help='Hostname of CUPS server (optional)', metavar='HOSTNAME')parser.add_option('-P', '--port', action="store", type="int",dest='port', help='Port number of CUPS server', metavar='PORT')parser.add_option('-u', '--user', action="store", type="string",dest='username', help='Username to authenticate with against CUPS',metavar='USER')parser.add_option('-d', '--directory', action="store", type="string",dest='directory', help='Directory to create service files',metavar='DIRECTORY')parser.add_option('-v', '--verbose', action="store_true", dest="verbose",help="Print debugging information to STDERR")parser.add_option('-p', '--prefix', action="store", type="string",dest='prefix', help='Prefix all files with this string', metavar='PREFIX',default='AirPrint-')parser.add_option('-a', '--admin', action="store_true", dest="adminurl",help="Include the printer specified uri as the adminurl")(options, args) = parser.parse_args()# TODO XXX FIXME -- if cups login required, need to add# air=username,passwordfrom getpass import getpasscups.setPasswordCB(getpass)if options.directory:if not os.path.exists(options.directory):os.mkdir(options.directory)apg = AirPrintGenerate(user=options.username,host=options.hostname,port=options.port,verbose=options.verbose,directory=options.directory,prefix=options.prefix,adminurl=options.adminurl,)apg.generate()

4.运行脚本,得到*.service的文件,拷贝到/etc/avahi-deamon/service/下
如果提示运行脚本时候提示错误是关于MIME不能用于airprint,需要检查 /usr/share/cups/mime/是否有airprint.types和airprint.convs
5.重启cups和avahi-deamon服务,在ios设备上查找打印机
6.将avahi-deamon监听的端口加入防火墙的放行策略中,包括tcp和udp的端口,不然会造成打印机几次后,出现无法正常访问打印机

Centos7配置AirPrint(解决手机执行多次打印后搜索不到打印机的情况)相关推荐

  1. centos7配置不开启浏览器执行基于python+selenium的功能自动化脚本

    一)软件环境 python 3.7 selenium 3.11 geckodriver 0.21.0    //将其放置于/usr/bin目录下 firefox 62.0        //将其主目录 ...

  2. 阿里云服务器centos7配置Python Django项目

    阿里云服务器centos7配置Python Django项目 2020-3-25更新更换服务器后还原系统+相应配置 2019-12-13更新 Nginx域名绑定 2019-12-12更新 静态文件加载 ...

  3. 简单图文配置golang+vscode【win10/centos7+golang helloworld+解决install failed等情况】

    博客目录(阅读时间:10分钟) 一.win10 0.系统环境 1. win10配置golang环境 ①下载相关软件 ②创建gowork工作空间 ③配置环境变量(GOPATH+PATH) ④验证环境配置 ...

  4. android手机的扩容教程,解决手机系统空间不足

    android手机的扩容教程,解决手机系统空间不足问题 --通过将手机中的应用搬到SD卡中实现手机扩容 在智能手机中,android手机从市场占有率来看占有绝对优势,然而随着使用时间的增加,许多用户也 ...

  5. Centos7 配置 sendmail、postfix 端口号25、465

    阿里云.腾讯云的操作系统 CentOS 6.x 和 CentOS 7.x 安装 sendmail.postfix 发送邮件时,会遇到无法使用25端口号发送邮件的问题. 本文分享米扑博客折腾了几天的研究 ...

  6. CentOS-7 配置 SSH 远程登录

    CentOS-7 配置 SSH 远程登录 CentOS 配置 SSH 远程登录 一.环境 二.配置网络 1.检查网络状态 2.下载 net-tools 工具 3.检查主机与虚拟机是否正常连通 三.SS ...

  7. 彻底解决手机相册照片顺序乱的三种方法

    想着偷偷懒,用用一键换机功能来转移手机的三千张照片吧,结果就踩坑了,照片顺序全部被打乱,然后分析了原因,搞了一晚上才解决好.总结出来3种解决办法 一键换机并不完美 前段时间换了新手机,听大家说MIUI ...

  8. centos7配置web服务器

    centos7配置web服务器 准备 环境: ​ VMware Workstation Pro ​ Linux/CentOS-7-x86_64-DVD-2009.iso ​ 安装省略(有手就行) 配置 ...

  9. js手机键盘遮挡_完美解决手机网页中输入框被输入法遮挡的问题

    之前要做一个弹出对话框,填写信息,发现在手机上看的时候,较后的输入框在填写信息时,输入框被输入法遮挡,只能盲填. 前提 1.弹出的对话框用display:fixed定位的 2.对话框大小固定 解决办法 ...

  10. python运行非常慢的解决-python执行太慢

    广告关闭 腾讯云双11爆品提前享,精选热门产品助力上云,云服务器首年88元起,买的越多返的越多,最高满返5000元! 假如 load 完成还没计算,这时候线程切换了,其他线程修改了 a 的值,然后切换 ...

最新文章

  1. 质数判断及质因数分解 质数是指在大于1的自然数中,除了1和它本身以外不再有其他因数的自然数。 0和1不是质数 除了0,1,质数以外其他的数叫合数
  2. 为你分享10篇NLP、CV领域优质论文
  3. 世界人口钟实时数据_用数字孪生重新定义智慧城市,美象VR推出MxDATA智慧城市CIM数据可视化平台...
  4. condition框架设计与实现
  5. 收集经常使用的.net开源项目
  6. 【数据结构】对快速排序原理的理解(图解,通俗易懂)
  7. 马大为院士:科研人也得养家, 非升即走压力下,不得不做短平快的研究
  8. 如何编写自定义的Web控件
  9. 40_并发编程-事件
  10. JQuery选择器中含有冒号的ID处理差异的分析
  11. 系统功能调用DOS中断INT 21H功能包单字符输入01单字符输出02字符串输入0a字符串输出09
  12. 【绝密外泄】风哥Oracle数据库DBA高级工程师培训视频教程与内部资料v0.1
  13. 如何拆分PDF成单页?这三个方法分享给你
  14. 《深度剖析U8系统前后台数据关系》课程简介
  15. Tiny Heroes:道高一尺,魔高一丈
  16. python判断两个数是否互质_《算法》第一章——判断两个整数是否互质
  17. 坐标系基础相关知识:右手定则
  18. 单片机音频节奏灯_使LED灯随音乐闪烁的控制方法及音乐节奏闪灯技术
  19. 查询日期是该年的多少天
  20. MATLAB设计模糊控制器并用simulink仿真

热门文章

  1. 航空三字代码表_航空公司二字及三字代码表
  2. 为什么都不想去中科创达_那些过年不想回家的人,都去了哪?
  3. 在delphi的dbgrid中插入其他可视组件_delphi教程
  4. android 音频压缩 silk,微信音频silk导出多个mp3,合并成一个mp3,压缩大小
  5. 怎么查看文件的MD5码
  6. AIDA64 Business Edition(系统检测)多国语言绿色特别
  7. 软考网络工程师易错100问
  8. 重定向,用户管理,密码管理,权限管理
  9. telnet命令用法举例
  10. PostgreSQL-客户端安装