我有一些我想用zeroconf看到的应用程序。
Python或sh是首选。特定于操作系统的建议欢迎使用Linux和OS X.
答案 0 :(得分:9)
或者你可以使用bash:
dns-sd -R <Name> <Type> <Domain> <Port> [<TXT>...]
默认情况下,这在OS X上有效。对于其他* nix,请参阅avahi-publish手册页(您可能需要通过首选软件包管理器安装)。
答案 1 :(得分:8)
我建议pybonjour。
答案 2 :(得分:8)
pip install zeroconf
以下是我用来向iOS设备宣布Twisted-Autobahn WebSocket的脚本的摘录:
from zeroconf import ServiceInfo, Zeroconf
class WebSocketManager(service.Service, object):
ws_service_name = 'Verasonics WebSocket'
wsPort = None
wsInfo = None
def __init__(self, factory, portCallback):
factory.protocol = BroadcastServerProtocol
self.factory = factory
self.portCallback = portCallback
self.zeroconf = Zeroconf()
def privilegedStartService(self):
self.wsPort = reactor.listenTCP(0, self.factory)
port = self.wsPort.getHost().port
fqdn = socket.gethostname()
ip_addr = socket.gethostbyname(fqdn)
hostname = fqdn.split('.')[0]
wsDesc = {'service': 'Verasonics Frame', 'version': '1.0.0'}
self.wsInfo = ServiceInfo('_verasonics-ws._tcp.local.',
hostname + ' ' + self.ws_service_name + '._verasonics-ws._tcp.local.',
socket.inet_aton(ip_addr), port, 0, 0,
wsDesc, hostname + '.local.')
self.zeroconf.register_service(self.wsInfo)
self.portCallback(port)
return super(WebSocketManager, self).privilegedStartService()
def stopService(self):
self.zeroconf.unregister_service(self.wsInfo)
self.wsPort.stopListening()
return super(WebSocketManager , self).stopService()
答案 3 :(得分:1)
通过Avahi Python bindings,这很容易。