Skip to content

Commit 2ca8fbf

Browse files
committed
update README of modules
1 parent bf2bab9 commit 2ca8fbf

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

modules/README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Therefore, here is the structure of the Lua script you pass to bulkDNS.
3636

3737

3838
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)
4040
-- you passed to bulkDNS
4141

4242
-- body of the function
@@ -53,6 +53,10 @@ It's also very important to note that whatever global variable you define in you
5353
until the end of the scan. This is on purpose! In this way, you can keep the states for different entries
5454
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!
5555

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+
5660
#### First example: find NXdomains
5761

5862
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")
6670
assert(sdns)
6771

6872
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+
6976
-- create a query packet
7077
local query = sdns.create_query(line, "A", "IN")
7178
-- make sure the query packet created successfully
@@ -156,6 +163,7 @@ local json_encode = json.encode
156163
local insert = table.insert
157164

158165
function main(line)
166+
if line == nil then return nil end
159167
local query = sdns.create_query(line, "TXT", "IN")
160168
if query == nil then return nil end
161169
tbl_send = {dstport=53, timeout=3, dstip="1.1.1.1"}

0 commit comments

Comments
 (0)