@@ -36,7 +36,7 @@ Therefore, here is the structure of the Lua script you pass to bulkDNS.
36
36
37
37
38
38
function main (input_line )
39
- -- input_line: one of the entries of the input file
39
+ -- input_line: one of the entries of the input file or nil (only for the last call)
40
40
-- you passed to bulkDNS
41
41
42
42
-- body of the function
@@ -53,6 +53,10 @@ It's also very important to note that whatever global variable you define in you
53
53
until the end of the scan. This is on purpose! In this way, you can keep the states for different entries
54
54
and have a dynamic scan. For examle, one use-case of this feature is to implement a global LRU DNS cache in your Lua file!
55
55
56
+ When there is no more entry for scan, the C code will call the Lua 'main' function for the last time by passing ` nil ` to the
57
+ main function. With this last call, the Lua script knows that it's time to save global variables or do whatever you want since
58
+ there won't be any other call to.
59
+
56
60
#### First example: find NXdomains
57
61
58
62
Here is the scan scenario: I have a list of domain names and I want to output only those with DNS response code of NXDomain.
@@ -66,6 +70,9 @@ local sdns = require("libsdns")
66
70
assert (sdns )
67
71
68
72
function main (line )
73
+ -- we don't care about the last call as we don't have global vars
74
+ if line == nil then return nil end
75
+
69
76
-- create a query packet
70
77
local query = sdns .create_query (line , " A" , " IN" )
71
78
-- make sure the query packet created successfully
@@ -156,6 +163,7 @@ local json_encode = json.encode
156
163
local insert = table.insert
157
164
158
165
function main (line )
166
+ if line == nil then return nil end
159
167
local query = sdns .create_query (line , " TXT" , " IN" )
160
168
if query == nil then return nil end
161
169
tbl_send = {dstport = 53 , timeout = 3 , dstip = " 1.1.1.1" }
0 commit comments