@@ -241,11 +241,11 @@ def whois(
241241 nhost = None
242242 response_str = response .decode ("utf-8" , "replace" )
243243 if 'with "=xxx"' in response_str :
244- return self .whois (query , hostname , flags , True , quiet = quiet , ignore_socket_errors = ignore_socket_errors )
244+ return self .whois (query , hostname , flags , True , quiet = quiet , ignore_socket_errors = ignore_socket_errors , timeout = timeout )
245245 if flags & NICClient .WHOIS_RECURSE and nhost is None :
246246 nhost = self .findwhois_server (response_str , hostname , query )
247247 if nhost is not None and nhost != "" :
248- response_str += self .whois (query , nhost , 0 , quiet = quiet , ignore_socket_errors = ignore_socket_errors )
248+ response_str += self .whois (query , nhost , 0 , quiet = quiet , ignore_socket_errors = ignore_socket_errors , timeout = timeout )
249249 except socket .error as e :
250250 if not quiet :
251251 logger .error (
@@ -416,7 +416,7 @@ def choose_server(self, domain: str) -> Optional[str]:
416416 # return server
417417
418418 def whois_lookup (
419- self , options : Optional [dict ], query_arg : str , flags : int , quiet : bool = False , ignore_socket_errors : bool = True
419+ self , options : Optional [dict ], query_arg : str , flags : int , quiet : bool = False , ignore_socket_errors : bool = True , timeout : int = 10
420420 ) -> str :
421421 """Main entry point: Perform initial lookup on TLD whois server,
422422 or other server to get region-specific whois server, then if quick
@@ -444,16 +444,17 @@ def whois_lookup(
444444 options ["country" ] + NICClient .QNICHOST_TAIL ,
445445 flags ,
446446 quiet = quiet ,
447- ignore_socket_errors = ignore_socket_errors
447+ ignore_socket_errors = ignore_socket_errors ,
448+ timeout = timeout
448449 )
449450 elif self .use_qnichost :
450451 nichost = self .choose_server (query_arg )
451452 if nichost is not None :
452- result = self .whois (query_arg , nichost , flags , quiet = quiet , ignore_socket_errors = ignore_socket_errors )
453+ result = self .whois (query_arg , nichost , flags , quiet = quiet , ignore_socket_errors = ignore_socket_errors , timeout = timeout )
453454 else :
454455 result = ""
455456 else :
456- result = self .whois (query_arg , options ["whoishost" ], flags , quiet = quiet , ignore_socket_errors = ignore_socket_errors )
457+ result = self .whois (query_arg , options ["whoishost" ], flags , quiet = quiet , ignore_socket_errors = ignore_socket_errors , timeout = timeout )
457458 return result
458459
459460
@@ -599,6 +600,14 @@ def parse_command_line(argv: list[str]) -> tuple[optparse.Values, list[str]]:
599600 dest = "whoishost" ,
600601 help = "Lookup using host " + NICClient .PANDIHOST ,
601602 )
603+ parser .add_option (
604+ "-t" ,
605+ "--timeout" ,
606+ action = "store" ,
607+ type = "int" ,
608+ dest = "timeout" ,
609+ help = "Set timeout for WHOIS request" ,
610+ )
602611 parser .add_option ("-?" , "--help" , action = "help" )
603612
604613 return parser .parse_args (argv )
0 commit comments