Example #1
0
 def parse_srv_result(self, fqdn, result):
     """
     Parse the output of host command and return list of properties:
     'host', 'port','weight', 'priority' corresponding to the found srv hosts
     """
     # typical output of host command:
     # _xmpp-client._tcp.jabber.org has SRV record 30 30 5222 jabber.org.
     if not result:
         return []
     ufqdn = helpers.ascii_to_idn(fqdn)  # Unicode domain name
     hosts = []
     lines = result.split('\n')
     for line in lines:
         if line == '':
             continue
         domain = None
         if line.startswith(fqdn):
             domain = fqdn  # For nslookup 9.5
         elif line.startswith(ufqdn):
             domain = ufqdn  # For nslookup 9.6
         if domain:
             # add 4 for ' has' after domain name
             rest = line[len(domain) + 4:].split('record')
             if len(rest) != 2:
                 continue
             answer_type, props_str = rest
             if answer_type.strip() != 'SRV':
                 continue
             props = props_str.strip().split(' ')
             if len(props) < 4:
                 continue
             prio, weight, port, host = props[-4:]
             if host[-1] == '.':
                 host = host[:-1]
             try:
                 prio = int(prio)
                 weight = int(weight)
                 port = int(port)
             except ValueError:
                 continue
             hosts.append({
                 'host': host,
                 'port': port,
                 'weight': weight,
                 'prio': prio
             })
     return hosts
Example #2
0
 def parse_srv_result(self, fqdn, result):
     """
     Parse the output of host command and return list of properties:
     'host', 'port','weight', 'priority' corresponding to the found srv hosts
     """
     # typical output of host command:
     # _xmpp-client._tcp.jabber.org has SRV record 30 30 5222 jabber.org.
     if not result:
         return []
     ufqdn = helpers.ascii_to_idn(fqdn) # Unicode domain name
     hosts = []
     lines = result.split('\n')
     for line in lines:
         if line == '':
             continue
         domain = None
         if line.startswith(fqdn):
             domain = fqdn # For nslookup 9.5
         elif helpers.decode_string(line).startswith(ufqdn):
             line = helpers.decode_string(line)
             domain = ufqdn # For nslookup 9.6
         if domain:
             # add 4 for ' has' after domain name
             rest = line[len(domain)+4:].split('record')
             if len(rest) != 2:
                 continue
             answer_type, props_str = rest
             if answer_type.strip() != 'SRV':
                 continue
             props = props_str.strip().split(' ')
             if len(props) < 4:
                 continue
             prio, weight, port, host  = props[-4:]
             if host[-1] == '.':
                 host = host[:-1]
             try:
                 prio = int(prio)
                 weight = int(weight)
                 port = int(port)
             except ValueError:
                 continue
             hosts.append({'host': host, 'port': port, 'weight': weight,
                     'prio': prio})
     return hosts
Example #3
0
 def _parse_srv_result_posix(self, fqdn, result):
     # typical output of bind-tools nslookup command:
     # _xmpp-client._tcp.jabber.org    service = 30 30 5222 jabber.org.
     if not result:
         return []
     ufqdn = helpers.ascii_to_idn(fqdn)  # Unicode domain name
     hosts = []
     lines = result.split('\n')
     for line in lines:
         if line == '':
             continue
         domain = None
         if line.startswith(fqdn):
             domain = fqdn
         elif helpers.decode_string(line).startswith(ufqdn):
             line = helpers.decode_string(line)
             domain = ufqdn
         if domain:
             rest = line[len(domain):].split('=')
             if len(rest) != 2:
                 continue
             answer_type, props_str = rest
             if answer_type.strip() != 'service':
                 continue
             props = props_str.strip().split(' ')
             if len(props) < 4:
                 continue
             prio, weight, port, host = props[-4:]
             if host[-1] == '.':
                 host = host[:-1]
             try:
                 prio = int(prio)
                 weight = int(weight)
                 port = int(port)
             except ValueError:
                 continue
             hosts.append({
                 'host': host,
                 'port': port,
                 'weight': weight,
                 'prio': prio
             })
     return hosts
Example #4
0
	def _parse_srv_result_posix(self, fqdn, result):
		# typical output of bind-tools nslookup command:
		# _xmpp-client._tcp.jabber.org    service = 30 30 5222 jabber.org.
		if not result: 
			return []
		ufqdn = helpers.ascii_to_idn(fqdn) # Unicode domain name
		hosts = []
		lines = result.split('\n')
		for line in lines:
			if line == '':
				continue
			domain = None
			if line.startswith(fqdn):
				domain = fqdn
			elif helpers.decode_string(line).startswith(ufqdn):
				line = helpers.decode_string(line)
				domain = ufqdn
			if domain:
				rest = line[len(domain):].split('=')
				if len(rest) != 2:
					continue
				answer_type, props_str = rest
				if answer_type.strip() != 'service':
					continue
				props = props_str.strip().split(' ')
				if len(props) < 4:
					continue
				prio, weight, port, host  = props[-4:]
				if host[-1] == '.':
					host = host[:-1]
				try:
					prio = int(prio)
					weight = int(weight)
					port = int(port)
				except ValueError:
					continue
				hosts.append({'host': host, 'port': port,'weight': weight,
						'prio': prio})
		return hosts
Example #5
0
 def _parse_srv_result_posix(self, fqdn, result):
     # typical output of bind-tools nslookup command:
     # _xmpp-client._tcp.jabber.org    service = 30 30 5222 jabber.org.
     if not result:
         return []
     ufqdn = helpers.ascii_to_idn(fqdn)  # Unicode domain name
     hosts = []
     lines = result.split("\n")
     for line in lines:
         if line == "":
             continue
         domain = None
         if line.startswith(fqdn):
             domain = fqdn  # For nslookup 9.5
         elif line.startswith(ufqdn):
             domain = ufqdn  # For nslookup 9.6
         if domain:
             rest = line[len(domain) :].split("=")
             if len(rest) != 2:
                 continue
             answer_type, props_str = rest
             if answer_type.strip() != "service":
                 continue
             props = props_str.strip().split(" ")
             if len(props) < 4:
                 continue
             prio, weight, port, host = props[-4:]
             if host[-1] == ".":
                 host = host[:-1]
             try:
                 prio = int(prio)
                 weight = int(weight)
                 port = int(port)
             except ValueError:
                 continue
             hosts.append({"host": host, "port": port, "weight": weight, "prio": prio})
     return hosts