Index: nse_nmaplib.cc =================================================================== --- nse_nmaplib.cc (revision 9443) +++ nse_nmaplib.cc (working copy) @@ -12,7 +12,9 @@ #include "Target.h" #include "output.h" #include "portlist.h" +#include "nmap_dns.h" + #define SCRIPT_ENGINE_GETSTRING(name) \ char* name; \ lua_getfield(L, -1, #name); \ @@ -43,6 +45,7 @@ static int l_get_have_ssl(lua_State *L); static int l_fetchfile(lua_State *L); static int l_get_timing_level(lua_State *L); +static int l_get_dns_servers(lua_State *L); int l_clock_ms(lua_State *L); @@ -132,6 +135,7 @@ {"fetchfile", l_fetchfile}, {"timing_level", l_get_timing_level}, {"mutex", l_mutex}, + {"get_dns_servers", l_get_dns_servers}, {NULL, NULL} }; @@ -636,3 +640,22 @@ lua_pushnumber(L, o.timing_level); return 1; } + +// returns a table with DNS servers known to nmap +static int l_get_dns_servers(lua_State *L) +{ + std::list servs2 = get_dns_servers(); + std::list::iterator servI2; + + int i = 1; + lua_newtable(L); + + for(servI2 = servs2.begin(); servI2 != servs2.end(); servI2++) { + lua_pushinteger(L, i); + const char *s = (*servI2).c_str(); + lua_pushstring(L, s); + lua_settable(L, -3); + i++; + } + return 1; +} Index: nmap_dns.cc =================================================================== --- nmap_dns.cc (revision 9443) +++ nmap_dns.cc (working copy) @@ -1326,3 +1326,20 @@ firstrun=0; } + +// Returns a list of known DNS servers +std::list get_dns_servers() { + // if, for example, run with -n, list is not initialized, + // run empty nmap_mass_rdns to do so + if(servs.size() == 0 && firstrun) { + nmap_mass_rdns(NULL, 0); + } + std::list::iterator servI; + std::list serverList; + dns_server *tpserv; + for(servI = servs.begin(); servI != servs.end(); servI++) { + tpserv = *servI; + serverList.push_back(inet_ntoa(tpserv->addr.sin_addr)); + } + return serverList; +} Index: nmap_dns.h =================================================================== --- nmap_dns.h (revision 9443) +++ nmap_dns.h (working copy) @@ -103,3 +103,4 @@ void free_dns_servers(); void free_etchosts(); +std::list get_dns_servers();