This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

Lua - passing arguments to a script

2

How can I pass arguments (from the command line) to a tshark/Lua script?
Specifically, I'm interested in having a DEBUG flag, that changes the script's logics.

asked 07 Dec '11, 07:51

Trevor's gravatar image

Trevor
41448
accept rate: 0%

edited 07 Dec '11, 07:52


3 Answers:

3

[This is a really old question, but I came upon it while searching through Lua-related questions and thought it should be updated]

The latest wireshark automated builds (nightly 1.11.3) have the ability to pass one or more arguments to a Lua script. It's done with a '-X lua_script[num]:arg' syntax, where [num] is replaced by an integer for which lua script to pass the argument to (since you can load multiple scripts). So the number needs to match which -X lua_script:filename it was, like so:

tshark -X lua_script:foo.lua -X lua_script:bar.lua -X lua_script1:arg1 -X lua_script2:arg2

In the above command, the string "arg1" is passed to the foo.lua script, while the string "arg2" is passed to the bar.lua script. If you had another '-X lua_script1:arg3' at the end, then the string "arg3" would be passed to foo.lua.

Note that inside your script (i.e., inside foo.lua or bar.lua) you access the passed-in arguments through the '...' Lua varargs notation. So like this:

-- put the passed-in args into a table
local args = {...}
-- print them out
for i,v in ipairs(args) do
    print("argument #" .. i .. " is:" .. v)
end

answered 07 Mar '14, 18:16

Hadriel's gravatar image

Hadriel
2.7k2939
accept rate: 18%

0

I recently learned how to make lua scripts for tshark. I believe I recall seeing in passing that passing args from command line to script cannot be done at this time. I don't recall where that was though.

answered 07 Dec '11, 13:19

studog's gravatar image

studog
16224
accept rate: 0%

0

Someone had asked this a while ago on one of the mailing lists...

The only way (AFAIK) to pass arguments to a WS Lua script is to use environment variables, as shown here:

$ echo "print('DEBUG', os.getenv('DEBUG'))" > test.lua
$ DEBUG=1 tshark -v -Xlua_script:test.lua 
DEBUG   1
TShark 1.7.1 (SVN Rev 39998 from /trunk)

Copyright 1998-2011 Gerald Combs <[email protected]> and contributors. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Compiled (64-bit) with GLib 2.28.8, with libpcap 1.1.1, with libz 1.2.5, without POSIX capabilities, with SMI 0.4.8, with c-ares 1.7.4, with Lua 5.1, with Python 2.7.1, with GnuTLS 2.8.6, with Gcrypt 1.5.0, with MIT Kerberos, with GeoIP.

Running on Mac OS 10.7.2 (Darwin 11.2.0), with locale en_US.UTF-8, with libpcap version 1.1.1, with libz 1.2.5.

Built using llvm-gcc 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00).

answered 07 Dec ‘11, 13:27

helloworld's gravatar image

helloworld
3.1k42041
accept rate: 28%