I'd like to programatically call wireshark to capture 100 packets, parse source mac address of each packet and close. How can I do this? This is what I have so far, but it's not working:
This is supposed to stop capturing after 100 packets, start capturing immediately, shut down wireshark after done, and print the output to stdout, which is the command prompt. Any help? http://www.wireshark.org/docs/wsug_html_chunked/ChCustCommandLine.html asked 22 Aug '11, 02:43 tonio09 edited 22 Aug '11, 17:43 cmaynard ♦♦ |
2 Answers:
You can also use TShark. This command line tool is shipped together with Wireshark. answered 22 Aug '11, 03:58 joke |
Actually, you should use tshark for this. Like so:
which spits out the mac source list on standard out. answered 22 Aug '11, 06:01 Jaap ♦ But specifying the " (22 Aug '11, 16:30) cmaynard ♦♦ If it truly crashes, that's a functional bug. I tried it with SVN 38652 on OS X, and it popped up a complaint that "-" isn't a regular file (even though I'd redirected the standard output to a file), but spewed out a ton of "poll(2) failed due to: Bad file descriptor" complaints. "-w -" should only work if the standard output is redirected to a file; it should fail otherwise. The person who asked the question apparently thought it'd write parsed output to the standard output; it will, of course, do no such thing. (22 Aug '11, 17:24) Guy Harris ♦♦ True. It's definitely a functional bug. I guess my question is whether there's also a documentation bug, but it wouldn't appear so. Anyway, I opened bug 6256 for the crash. (22 Aug '11, 17:58) cmaynard ♦♦ We've fixed the crash. However, it's not clear that -Q is a useful option, as per all the notes above that TShark is the right program to use here and that Wireshark won't do what you want. Unless somebody can come up with a case where -Q is useful - i.e., where it's useful to have the GUI running while the capture is in progress, but not when the capture stops - we're probably going to eliminate it. (23 Aug '11, 20:02) Guy Harris ♦♦ |
The documentation you quote says that "-w -" sets the "savefile" to -, i.e. to the standard output". That's "savefile" in the tcpdump sense, i.e. it's a raw pcap or pcap-ng capture file, not some nice human-readable printed output.
You don't want Wireshark for this, you want TShark (which, unlike Wireshark, is intended to write dissected packets to the standard output), as the answers say.