diff --git a/scripts/broadcast-tellstick-discover.nse b/scripts/broadcast-tellstick-discover.nse index 46ae55f28..e9568a078 100644 --- a/scripts/broadcast-tellstick-discover.nse +++ b/scripts/broadcast-tellstick-discover.nse @@ -8,10 +8,11 @@ Discovers Telldus Technologies TellStickNet devices on the LAN. -- -- @output -- | broadcast-tellstick-discover: --- | Product: TellStickNet --- | MAC: ACCA12345678 --- | Activation code: 8QABCDEFGH --- |_ Version: 3 +-- | 192.168.0.100 +-- | Product: TellStickNet +-- | MAC: ACCA12345678 +-- | Activation code: 8QABCDEFGH +-- |_ Version: 3 -- author = "Patrik Karlsson" @@ -20,8 +21,6 @@ categories = {"broadcast", "safe"} prerule = function() return ( nmap.address_family() == 'inet' ) end -local function fail(err) return ("\n ERROR: %s"):format(err or "") end - action = function() local socket = nmap.new_socket("udp") local host, port = { ip = "255.255.255.255" }, { number = 30303, protocol = "udp" } @@ -31,21 +30,34 @@ action = function() return fail("Failed to send discovery request to server") end - local status, response = socket:receive() - if ( not(status) ) then - return fail("Failed to receive response from server") - end + local output = {} - local prod, mac, activation, version = response:match("^([^:]*):([^:]*):([^:]*):([^:]*)$") - if ( not(prod) or not(mac) or not(activation) or not(version) ) then - return + while( true ) do + local status, response = socket:receive() + if ( not(status) ) then + break + end + + local status, _, _, ip = socket:get_info() + if ( not(status) ) then + stndse.print_debug(2, "Failed to get socket information") + break + end + + local prod, mac, activation, version = response:match("^([^:]*):([^:]*):([^:]*):([^:]*)$") + if ( prod and mac and activation and version ) then + local output_part = { + name = ip, + ("Product: %s"):format(prod), + ("MAC: %s"):format(mac), + ("Activation code: %s"):format(activation), + ("Version: %s"):format(version) + } + table.insert(output, output_part) + end end - local output = { - ("Product: %s"):format(prod), - ("MAC: %s"):format(mac), - ("Activation code: %s"):format(activation), - ("Version: %s"):format(version) - } - return stdnse.format_output(true, output) + if ( 0 < #output ) then + return stdnse.format_output(true, output) + end end \ No newline at end of file