Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
record.alias == info.name):
if info.name.find('.') < 0:
info.name = '%s.[%s:%s].%s' % (info.name,
info.address, info.port, info.type)
self.checkService(info)
return
raise NonUniqueNameException
if now < nextTime:
self.wait(nextTime - now)
now = currentTimeMillis()
continue
out = DNSOutgoing(_FLAGS_QR_QUERY | _FLAGS_AA)
self.debug = out
out.addQuestion(DNSQuestion(info.type, _TYPE_PTR, _CLASS_IN))
out.addAuthorativeAnswer(DNSPointer(info.type, _TYPE_PTR,
_CLASS_IN, _DNS_TTL, info.name))
self.send(out)
i += 1
nextTime += _CHECK_TIME
if self.servicetypes[info.type]>1:
self.servicetypes[info.type]-=1
else:
del self.servicetypes[info.type]
except:
pass
now = currentTimeMillis()
nextTime = now
i = 0
while i < 3:
if now < nextTime:
self.wait(nextTime - now)
now = currentTimeMillis()
continue
out = DNSOutgoing(_FLAGS_QR_RESPONSE | _FLAGS_AA)
out.addAnswerAtTime(DNSPointer(info.type, _TYPE_PTR,
_CLASS_IN, 0, info.name), 0)
out.addAnswerAtTime(DNSService(info.name, _TYPE_SRV,
_CLASS_IN, 0, info.priority, info.weight, info.port,
info.name), 0)
out.addAnswerAtTime(DNSText(info.name, _TYPE_TXT, _CLASS_IN,
0, info.text), 0)
if info.address:
out.addAnswerAtTime(DNSAddress(info.server, _TYPE_A,
_CLASS_IN, 0, info.address), 0)
self.send(out)
i += 1
nextTime += _UNREGISTER_TIME
def unregisterAllServices(self):
"""Unregister all registered services."""
if len(self.services) > 0:
now = currentTimeMillis()
nextTime = now
i = 0
while i < 3:
if now < nextTime:
self.wait(nextTime - now)
now = currentTimeMillis()
continue
out = DNSOutgoing(_FLAGS_QR_RESPONSE | _FLAGS_AA)
for info in self.services.values():
out.addAnswerAtTime(DNSPointer(info.type, _TYPE_PTR,
_CLASS_IN, 0, info.name), 0)
out.addAnswerAtTime(DNSService(info.name, _TYPE_SRV,
_CLASS_IN, 0, info.priority, info.weight,
info.port, info.server), 0)
out.addAnswerAtTime(DNSText(info.name, _TYPE_TXT,
_CLASS_IN, 0, info.text), 0)
if info.address:
out.addAnswerAtTime(DNSAddress(info.server,
_TYPE_A, _CLASS_IN, 0, info.address), 0)
self.send(out)
i += 1
nextTime += _UNREGISTER_TIME
if self.servicetypes[info.type] > 1:
self.servicetypes[info.type] -= 1
else:
del self.servicetypes[info.type]
except:
pass
now = currentTimeMillis()
nextTime = now
i = 0
while i < 3:
if now < nextTime:
self.wait(nextTime - now)
now = currentTimeMillis()
continue
out = DNSOutgoing(_FLAGS_QR_RESPONSE | _FLAGS_AA)
out.addAnswerAtTime(DNSPointer(info.type, _TYPE_PTR,
_CLASS_IN, 0, info.name), 0)
out.addAnswerAtTime(DNSService(info.name, _TYPE_SRV,
_CLASS_IN, 0, info.priority, info.weight, info.port,
info.name), 0)
out.addAnswerAtTime(DNSText(info.name, _TYPE_TXT, _CLASS_IN,
0, info.text), 0)
if info.address:
out.addAnswerAtTime(DNSAddress(info.server, _TYPE_A,
_CLASS_IN, 0, info.address), 0)
self.send(out)
i += 1
nextTime += _UNREGISTER_TIME
record.alias == info.name):
if info.name.find('.') < 0:
info.name = '%s.[%s:%s].%s' % (info.name,
info.address, info.port, info.type)
self.checkService(info)
return
raise NonUniqueNameException
if now < nextTime:
self.wait(nextTime - now)
now = currentTimeMillis()
continue
out = DNSOutgoing(_FLAGS_QR_QUERY | _FLAGS_AA)
self.debug = out
out.addQuestion(DNSQuestion(info.type, _TYPE_PTR, _CLASS_IN))
out.addAuthorativeAnswer(DNSPointer(info.type, _TYPE_PTR,
_CLASS_IN, _DNS_TTL, info.name))
self.send(out)
i += 1
nextTime += _CHECK_TIME
def readOthers(self):
"""Reads the answers, authorities and additionals section of the
packet"""
n = self.numAnswers + self.numAuthorities + self.numAdditionals
for i in xrange(n):
domain = self.readName()
type, clazz, ttl, length = self.unpack('!HHiH')
rec = None
if type == _TYPE_A:
rec = DNSAddress(domain, type, clazz, ttl, self.readString(4))
elif type == _TYPE_CNAME or type == _TYPE_PTR:
rec = DNSPointer(domain, type, clazz, ttl, self.readName())
elif type == _TYPE_TXT:
rec = DNSText(domain, type, clazz, ttl, self.readString(length))
elif type == _TYPE_SRV:
rec = DNSService(domain, type, clazz, ttl,
self.readUnsignedShort(), self.readUnsignedShort(),
self.readUnsignedShort(), self.readName())
elif type == _TYPE_HINFO:
rec = DNSHinfo(domain, type, clazz, ttl,
self.readCharacterString(), self.readCharacterString())
elif type == _TYPE_AAAA:
rec = DNSAddress(domain, type, clazz, ttl, self.readString(16))
else:
# Try to ignore types we don't know about
# Skip the payload for the resource record so the next
# records can be parsed correctly
self.offset += length
for question in msg.questions:
if question.type == _TYPE_PTR:
if question.name == "_services._dns-sd._udp.local.":
for stype in self.servicetypes.keys():
if out is None:
out = DNSOutgoing(_FLAGS_QR_RESPONSE | _FLAGS_AA)
out.addAnswer(msg,
DNSPointer("_services._dns-sd._udp.local.",
_TYPE_PTR, _CLASS_IN, _DNS_TTL, stype))
for service in self.services.values():
if question.name == service.type:
if out is None:
out = DNSOutgoing(_FLAGS_QR_RESPONSE | _FLAGS_AA)
out.addAnswer(msg,
DNSPointer(service.type, _TYPE_PTR,
_CLASS_IN, _DNS_TTL, service.name))
else:
try:
if out is None:
out = DNSOutgoing(_FLAGS_QR_RESPONSE | _FLAGS_AA)
# Answer A record queries for any service addresses we know
if question.type in (_TYPE_A, _TYPE_ANY):
for service in self.services.values():
if service.server == question.name.lower():
out.addAnswer(msg, DNSAddress(question.name,
_TYPE_A, _CLASS_IN | _CLASS_UNIQUE,
_DNS_TTL, service.address))
service = self.services.get(question.name.lower(), None)
if not service: continue
def readOthers(self):
"""Reads the answers, authorities and additionals section of the
packet"""
n = self.numAnswers + self.numAuthorities + self.numAdditionals
for i in xrange(n):
domain = self.readName()
type, clazz, ttl, length = self.unpack('!HHiH')
rec = None
if type == _TYPE_A:
rec = DNSAddress(domain, type, clazz, ttl, self.readString(4))
elif type == _TYPE_CNAME or type == _TYPE_PTR:
rec = DNSPointer(domain, type, clazz, ttl, self.readName())
elif type == _TYPE_TXT:
rec = DNSText(domain, type, clazz, ttl, self.readString(length))
elif type == _TYPE_SRV:
rec = DNSService(domain, type, clazz, ttl,
self.readUnsignedShort(), self.readUnsignedShort(),
self.readUnsignedShort(), self.readName())
elif type == _TYPE_HINFO:
rec = DNSHinfo(domain, type, clazz, ttl,
self.readCharacterString(), self.readCharacterString())
elif type == _TYPE_AAAA:
rec = DNSAddress(domain, type, clazz, ttl, self.readString(16))
else:
# Try to ignore types we don't know about
# Skip the payload for the resource record so the next
# records can be parsed correctly
self.offset += length
def __eq__(self, other):
"""Tests equality on alias"""
return isinstance(other, DNSPointer) and self.alias == other.alias