Skip to content

Commit f089435

Browse files
Merge pull request #306 from KGuillaume-chaps/master
Use given timeout when determining whois server
2 parents 8c44cab + c6381db commit f089435

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

whois/whois.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ def get_socket():
180180
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
181181
return s
182182

183-
def findwhois_iana(self, tld: str) -> Optional[str]:
183+
def findwhois_iana(self, tld: str, timeout: int = 10) -> Optional[str]:
184184
s = self.get_socket()
185-
s.settimeout(10)
185+
s.settimeout(timeout)
186186
s.connect(("whois.iana.org", 43))
187187
s.send(bytes(tld, "utf-8") + b"\r\n")
188188
response = b""
@@ -264,7 +264,7 @@ def whois(
264264
s.close()
265265
return response_str
266266

267-
def choose_server(self, domain: str) -> Optional[str]:
267+
def choose_server(self, domain: str, timeout: int = 10) -> Optional[str]:
268268
"""Choose initial lookup NIC host"""
269269
domain = domain.encode("idna").decode("utf-8")
270270
if domain.endswith("-NORID"):
@@ -413,7 +413,7 @@ def choose_server(self, domain: str) -> Optional[str]:
413413
elif tld == "xyz":
414414
return NICClient.XYZ_HOST
415415
else:
416-
return self.findwhois_iana(tld)
416+
return self.findwhois_iana(tld, timeout=timeout)
417417
# server = tld + NICClient.QNICHOST_TAIL
418418
# try:
419419
# socket.gethostbyname(server)
@@ -454,7 +454,7 @@ def whois_lookup(
454454
timeout=timeout
455455
)
456456
elif self.use_qnichost:
457-
nichost = self.choose_server(query_arg)
457+
nichost = self.choose_server(query_arg, timeout=timeout)
458458
if nichost is not None:
459459
result = self.whois(query_arg, nichost, flags, quiet=quiet, ignore_socket_errors=ignore_socket_errors, timeout=timeout)
460460
else:

0 commit comments

Comments
 (0)