0
votes

I am trying to capture a CDP packet with Tshark commandline application and either redirect the output to my C# console program or to a file that I can then read into my application. This does not work. I am running Windows 10 version 1703.

I have verified in a commandline prompt that the specific tshark command works and that I get the correct output for the CDP packet, however when I try to redirect the output in the commandline prompt, a file gets written, but no data gets written. This issue also occurs in my C# console application and it happens whether or not I redirect the output to my console or to a file. I have read somewhere (can't remember where) that tshark might have an issue with redirecting output, do you know if this is true? I have also tried redirecting output by writing a file with the tshark -W "filename.txt" command (same result with .pcap). This fails as well.

// Nic.Name = Ethernet (the network card I am capturing packet from)

// In the code below I am trying to redirect the output from the tshark command to my console application.

                    ProcessStartInfo psi = new ProcessStartInfo();
                        psi.FileName = @"C:\tshark\\tshark.exe";
                        psi.Arguments = "-i " + nic.Name + " 
                        ether[16:4] = 0x0300000C and ether[20:2] == 0x2000";
                        psi.UseShellExecute = false;
                        psi.RedirectStandardOutput = true;
                        psi.CreateNoWindow = true;
                        Process tsharkProcess = Process.Start(psi);
                        string s = tsharkProcess.StandardOutput.ReadToEnd();
                        Console.WriteLine(s);

I expect the output to be something like this (a commandline window should not appear when running the tshark command, this should run in the background):

Capturing on 'Ethernet' 1 0.000000 d0:c7:89:1c:55:19 → 01:00:0c:cc:cc:cc CDP 492 Device ID: SW1.local.it Port ID: GigabitEthernet1/0/25

I get the following output:

Capturing on 'Ethernet'

I get no error messages.

1

1 Answers

0
votes

I have found the issue. I was missing either a .dll or .exe file that tshark depends on for writing files. Writing to a file works now, but I did not get redirection to console to work.