我最妥善地解决了这一问题,因为我给这项任务的时间很少。
但不幸的是,我并不认为瓦希/米德斯/博奈尔的窗口是支持别).的(如果我错过如何支持这种做法的例子的话,我就认为了这一点)。
i网站提供的假冒文字开始做什么:
Create : /usr/bin/avahi-announce-alias
使之可执行;
#! /usr/bin/env python
# avahi-alias.py
import avahi, dbus
from encodings.idna import ToASCII
# Got these from /usr/include/avahi-common/defs.h
CLASS_IN = 0x01
TYPE_CNAME = 0x05
TTL = 60
def publish_cname(cname):
bus = dbus.SystemBus()
server = dbus.Interface(bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER),
avahi.DBUS_INTERFACE_SERVER)
group = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.EntryGroupNew()),
avahi.DBUS_INTERFACE_ENTRY_GROUP)
rdata = createRR(server.GetHostNameFqdn())
cname = encode_dns(cname)
group.AddRecord(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, dbus.UInt32(0),
cname, CLASS_IN, TYPE_CNAME, TTL, rdata)
group.Commit()
def encode_dns(name):
out = []
for part in name.split( . ):
if len(part) == 0: continue
out.append(ToASCII(part))
return . .join(out)
def createRR(name):
out = []
for part in name.split( . ):
if len(part) == 0: continue
out.append(chr(len(part)))
out.append(ToASCII(part))
out.append( )
return .join(out)
if __name__ == __main__ :
import time, sys, locale
for each in sys.argv[1:]:
name = unicode(each, locale.getpreferredencoding())
publish_cname(name)
try:
# Just loop forever
while 1: time.sleep(60)
except KeyboardInterrupt:
print "Exiting"
This script handles the announcement of each individual alias, and will remain running until you kill it.
(because of this, we need to create another script which I ve shown below)
Create text file /etc/avahi/aliases
我们用的是每条线向该机器储存一台货箱。
Create directory /etc/avahi/aliases.d/
我实际上没有在我在这里所展示的任何文字中加以利用,但是,对于那些从那里入手的人来说,你可以看到需要做些什么。
想法是,你可以把别的物品编成单独的文本档案(如果你处理藏匿的虚拟主人的话,会更有意义),这是许多关于*nix的 da魔应用已经提供的。
Create /usr/bin/avahi-announce-aliases
使之可执行并填满
#!/usr/bin/env python
import os, sys
from subprocess import Popen
def ensure_file (path):
"""
Looks for file at provided path, creates it if it does not exist.
Returns the file.
"""
rfile = None
if not os.path.exists(path) and os.path.isfile(path) :
rfile = open(path,"w+");
print("ensuring file : %s " % path)
print("file ensured : %s " % path)
return rfile
command = /usr/bin/avahi-announce-alias
alias_pid_path = "/tmp/avahi-aliases.pid"
alias_file_path = "/etc/avahi/aliases"
alias_file = open(alias_file_path)
if not os.path.exists(alias_pid_path) :
open(alias_pid_path,"w").close()
alias_pid = open(alias_pid_path,"r")
for line in alias_pid :
txt = line.strip(
)
if len(txt) > 0 :
print("kill %s" % txt )
os.system("kill %s" % txt)
alias_pid.close()
alias_pid = open(alias_pid_path,"w+")
for line in alias_file :
txt = line.strip(
)
if len(txt) > 0 :
print("publishing : << %s >>" % txt)
process = Popen([command, txt])
alias_pid.write("%s
" % str(process.pid))
alias_pid.close()
print("done")
这绝不意味着是假日方案拟订的主轴,因此,如果你认为合适,就可自由作出改进。
Usage
如果我们的东道国名是“服务器”,瓦希-东道国名是“服务器”。 附有您额外东道方名的案文:
deluge.server.local
username.server.local
accounts.server.local
something-else.server.local
another.hostname.home
(然而,我确实确信,如果你确信该网络已经不存在的话,你会在那里拥有任何东道名称,这就是为什么我只是创造出正常的瓦希东道国名的子库)
然后,我们运行:
。
我之所以设立这一职位,主要是因为便利了对django &的模拟;在我的膝上型计算机上开发破产网站。
Caveats
My only disappointment is that the windows implementation of Bonjour/Avahi does not support the aliases that this implementation announces, it will only see the main avahi hostname normally announced (ie server.local in our example above).