@@ -226,6 +226,13 @@ class SessionUI(BaseUI):
226226 def __init__ (self , height , width , server_count ):
227227 BaseUI .__init__ (self , curses .newwin (height - server_count - 3 , width , server_count + 3 , 0 ))
228228 self .sessions = [[] for i in range (server_count )]
229+ self .ip_to_hostname = {}
230+
231+ def hostname (self , session ):
232+ if session .host not in self .ip_to_hostname :
233+ hostname = socket .getnameinfo ((session .host , int (session .port )), 0 )[0 ]
234+ self .ip_to_hostname [session .host ] = hostname
235+ return self .ip_to_hostname [session .host ]
229236
230237 def update (self , s ):
231238 self .win .erase ()
@@ -238,10 +245,9 @@ def update(self, s):
238245 for i , session in enumerate (items ):
239246 try :
240247 #ugh, need to handle if slow - thread for async resolver?
241- if options .names :
242- session .host = socket .getnameinfo ((session .host , int (session .port )), 0 )[0 ]
248+ host = self .hostname (session ) if options .names else session .host
243249 self .addstr (i + 2 , 0 , "%-15s %5s %1s %1s %8s %8s %8s" %
244- (session . host [:15 ], session .port , session .server_id , session .interest_ops ,
250+ (host [:15 ], session .port , session .server_id , session .interest_ops ,
245251 session .queued , session .recved , session .sent ))
246252 except :
247253 break
0 commit comments