mirror of
https://github.com/ntop/ntopng.git
synced 2026-05-01 00:19:33 +00:00
Add REST endpoint for name resolution
This commit is contained in:
parent
0d07e5a699
commit
65acfacccd
2 changed files with 43 additions and 14 deletions
43
scripts/lua/rest/v1/get/dns/resolve.lua
Normal file
43
scripts/lua/rest/v1/get/dns/resolve.lua
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
--
|
||||
-- (C) 2013-20 - ntop.org
|
||||
--
|
||||
|
||||
dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
|
||||
require "lua_utils"
|
||||
local json = require ("dkjson")
|
||||
local rest_utils = require("rest_utils")
|
||||
|
||||
--
|
||||
-- Resolve a name
|
||||
-- Example: curl -u admin:admin -d '{"hostname" : "www.google.com"}' http://localhost:3000/lua/rest/v1/get/dns/resolve.lua
|
||||
--
|
||||
-- NOTE: in case of invalid login, no error is returned but redirected to login
|
||||
--
|
||||
|
||||
sendHTTPHeader('application/json')
|
||||
|
||||
local rc = rest_utils.consts_ok
|
||||
local res = {}
|
||||
|
||||
local hostname = _GET["hostname"]
|
||||
|
||||
if isEmptyString(hostname) then
|
||||
print(rest_utils.rc(rest_utils.consts_invalid_args))
|
||||
return
|
||||
end
|
||||
|
||||
local resolved = ntop.resolveHost(hostname, true --[[ IPv4 --]])
|
||||
if not resolved then
|
||||
resolved = ntop.resolveHost(hostname, false --[[ IPv6 --]])
|
||||
end
|
||||
|
||||
if not resolved then
|
||||
print(rest_utils.rc(rest_utils.consts_resolution_failed))
|
||||
return
|
||||
end
|
||||
|
||||
res = resolved
|
||||
|
||||
print(rest_utils.rc(rc, res))
|
||||
Loading…
Add table
Add a link
Reference in a new issue