<commit_before>local dns = require "dns"
local http = require "http"
local ipOps = require "ipOps"
local nmap = require "nmap"
local shortport = require "shortport"
local stdnse = require "stdnse"
local string = require "string"
local url = require "url"

description = [[
  Scans for Phillips Hue
]]

author = "<NAME>"

license = "Same as Nmap--See http://nmap.org/book/man-legal.html"

categories = {"default", "discovery", "safe"}

portrule = shortport.http

action = function(host, port)
  local resp, redirect_url, title

  resp = http.get( host, port, '/' )

  -- check for a redirect
--  if resp.location then
--    redirect_url = resp.location[#resp.location]
--    if resp.status and tostring( resp.status ):match( "30%d" ) then
--      return {redirect_url = redirect_url}, ("Did not follow redirect to %s"):format( redirect_url )
--    end
--  end

  if ( not(resp.body) ) then
    return
  end

  phillips = string.match(resp.body, 'hue personal wireless lighting')
  if not phillips then
    return
  end
  stdnse.print_debug(0, "Detected Phillips Hue")


  -- output a sMAP config file section
  local output_tab = stdnse.output_table()
  output_tab.type = 'smap.drivers.hue'
  output_tab.Metadata__Instrument__Manufacturer = 'Phillips'
  output_tab.Metadata__Instrument__Model = string.format('Hue')
  output_tab.ip = host.ip
  output_tab.Rate = 1

  output_tab.login = ''
  output_tab.password = ''

  -- local output_str = string.format("%s%s", major, minor)
  return output_tab
end<commit_msg>complete mandatory smap/hue driver ini fields in nmap output<commit_after>local dns = require "dns"
local http = require "http"
local ipOps = require "ipOps"
local nmap = require "nmap"
local shortport = require "shortport"
local stdnse = require "stdnse"
local string = require "string"
local url = require "url"

description = [[
  Scans for Phillips Hue
]]

author = "<NAME>"

license = "Same as Nmap--See http://nmap.org/book/man-legal.html"

categories = {"default", "discovery", "safe"}

portrule = shortport.http

action = function(host, port)
  local resp, redirect_url, title

  resp = http.get( host, port, '/' )

  if ( not(resp.body) ) then
    return
  end

  phillips = string.match(resp.body, 'hue personal wireless lighting')
  if not phillips then
    return
  end
  stdnse.print_debug(0, "Detected Phillips Hue")


  -- output a sMAP config file section
  local output_tab = stdnse.output_table()
  output_tab.type = 'smap.drivers.hue.Hue'
  output_tab.Metadata__Instrument__Manufacturer = 'Phillips'
  output_tab.Metadata__Instrument__Model = string.format('Hue')
  output_tab.ip = host.ip
  output_tab.Rate = 1
  output_tab.user = ''

  return output_tab
end
{'fraction_non_alphanumeric': 0.11863146150985497, 'fraction_numerical': 0.002231312755671253, 'mean_word_length': 3.908759124087591, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5271254', 'n_tokens_mistral': 921, 'n_tokens_neox': 897, 'n_words': 252}