@@ -72,26 +72,31 @@ def query(self, query, timeout=None, addr=None, edns=None):
7272 return defer .fail (failure .Failure (NotImplementedError (str (self .__class__ ) + " " + str (query .type ))))
7373
7474 def lookupAddress (self , name , timeout = None , addr = None , edns = None ):
75- if name in self .a_mapping :
76- ttl = self .a_mapping [name ]['ttl' ]
7775
78- def packResult (value ):
79- ret = []
80- add = []
81- for x in value :
82- ret .append (dns .RRHeader (name , dns .A , dns .IN , ttl , dns .Record_A (x , ttl ), True ))
76+ def packResult (value , ttl ):
77+ ret = []
78+ add = []
79+ for x in value :
80+ ret .append (dns .RRHeader (name , dns .A , dns .IN , ttl , dns .Record_A (x , ttl ), True ))
8381
84- if edns is not None :
85- if edns .rdlength > 8 :
86- add .append (dns .RRHeader ('' , sdns .EDNS , 4096 , edns .ttl , edns .payload , True ))
87- else :
88- add .append (dns .RRHeader ('' , sdns .EDNS , 4096 , 0 , sdns .Record_EDNS (None , 0 ), True ))
89- return [ret , (), add ]
82+ if edns is not None :
83+ if edns .rdlength > 8 :
84+ add .append (dns .RRHeader ('' , sdns .EDNS , 4096 , edns .ttl , edns .payload , True ))
85+ else :
86+ add .append (dns .RRHeader ('' , sdns .EDNS , 4096 , 0 , sdns .Record_EDNS (None , 0 ), True ))
87+ return [ret , (), add ]
9088
89+ wildcard = name [name .index ("." ):]
90+ if name in self .a_mapping :
91+ ttl = self .a_mapping [name ]['ttl' ]
9192 result = self .finder .findIP (str (addr [0 ]), name )
92- # 返回的IP数组乱序
93- random .shuffle (result )
94- return packResult (result )
93+ random .shuffle (result ) # 返回的IP数组乱序
94+ return packResult (result , ttl )
95+ elif wildcard in self .a_mapping :
96+ ttl = self .a_mapping [wildcard ]['ttl' ]
97+ result = self .finder .findIP (str (addr [0 ]), wildcard )
98+ random .shuffle (result ) # 返回的IP数组乱序
99+ return packResult (result , ttl )
95100 else :
96101 return self ._lookup (name , dns .IN , dns .A , timeout )
97102
0 commit comments