From c80a28f5f273745af071b4902b85787d07101654 Mon Sep 17 00:00:00 2001 From: patrik Date: Fri, 15 Jun 2012 21:26:26 +0000 Subject: [PATCH] Add netbios name lookup caching code in order to avoid multiple lookups for the same host.ip. --- nselib/smb.lua | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/nselib/smb.lua b/nselib/smb.lua index 14adaebc0..3b41a025d 100644 --- a/nselib/smb.lua +++ b/nselib/smb.lua @@ -278,11 +278,20 @@ function start(host) end -- Store the name of the server - status, result = netbios.get_server_name(host.ip) - if(status == true) then - state['name'] = result + local nbcache_mutex = nmap.mutex("Netbios lookup mutex") + nbcache_mutex "lock" + if ( not(host.registry['netbios_name']) ) then + status, result = netbios.get_server_name(host.ip) + if(status == true) then + host.registry['netbios_name'] = result + state['name'] = result + end + else + stdnse.print_debug(2, "SMB: Resolved netbios name from cache") + state['name'] = host.registry['netbios_name'] end - + nbcache_mutex "done" + stdnse.print_debug(2, "SMB: Starting SMB session for %s (%s)", host.name, host.ip) if(port == nil) then