2

I've created a simple TCP client and TCP server in Visual Studio using WCF. I have one simple operation on the server that receives an integer, increments it and sends it back. It works as expected.

I would like to use Wireshark to monitor traffic between the client and server running on localhost. Apparently this is not possible with the Wireshark standard install on Windows, as it cannot monitor the loopback adapter. There is a library called Npcap that is intended to solve this problem, so I have installed this:

Npcap on GitHub

When I run Wireshark, and select capture of the

Npcap Loopback Adapter

I do not see any TCP traffic (some UDP and DHCP only). I'm wondering what I would expect to see?

The C# code for the server is here (I've created it programmatically so that you can see all the details, there's nothing configured in App.Config)

using System;
using System.ServiceModel;
using System.ServiceModel.Description;

namespace TcpServer
{
    // Defining the service
    [ServiceContract]
    public interface ITcpService
    {
        [OperationContract]
        int GetNumber(int num);
    }

    // Implementing the service
    public class TcpService : ITcpService
    {
        public int GetNumber(int num)
        {
            return num + 1;
        }
    }

    class TcpServerConsole
    {
        static void Main(string[] args)
        {
            ServiceHost host;

            // Attempt to open the service
            try
            {
                // Create the service host with a Uri address and service description
                host = new ServiceHost(typeof(TcpService), new Uri("net.tcp://127.0.0.1:9000/MyService"));

                // Create the metadata that describes our service, add it to the service host
                var metadataBehavior = new ServiceMetadataBehavior() { HttpGetEnabled = false };
                host.Description.Behaviors.Add(metadataBehavior);

                // Add a tcp endpoint for our service, using tcp
                host.AddServiceEndpoint(typeof(ITcpService), new NetTcpBinding(), "");

                // Add the meta data service endpoint for describing the service
                var mexBinding = MetadataExchangeBindings.CreateMexTcpBinding();
                host.AddServiceEndpoint(typeof(IMetadataExchange), mexBinding, "net.tcp://127.0.0.1:9000/MyService/mex");

                // Open our service 
                host.Open();
            }
            catch (Exception e)
            {
                // Catch any problem with creating the service and report
                Console.WriteLine("Failed to open the server: {0}", e.Message);
                Console.WriteLine("Press [Return] to close");
                Console.ReadKey(true);
                return;
            }

            // Halt the program to keep the service open
            Console.WriteLine("Press [Return] to close server");
            Console.ReadKey(true);
            host.Close();
        }
    }
}
Matt Davis
  • 45,297
  • 16
  • 93
  • 124
Simon Bosley
  • 1,114
  • 3
  • 18
  • 41

1 Answers1

3

I'm the author of Npcap. First thanks for the report!

First I would like to mention that, the best way to get help about Npcap is using the mailing list: dev@nmap.org or firing a issue at https://github.com/nmap/nmap/issues. I check those places every day. I mostly use Stackoverflow for asking questions, but doesn't search and answer questions about Npcap that much.

I'm not an expert in C#. I have created a WCF Service Application project in my VS2015. Copied your code to my Service1.svc.cs. Build it into WcfService1.dll. But I don't know how to use it?

Would you mind providing all your server and client code (including solution files)? So I can just use them to test Npcap (no need to grab the knowledge about C# and WCF). You can zip the code and attach the zip in the mail to dev@nmap.org. I will reply it. Thanks!

hsluoyz
  • 2,739
  • 5
  • 35
  • 59
  • Many Thanks for responding to my question, I wasn't expecting the Author :-). I'll zip it up and send it over via WeTransfer, hopefully today. – Simon Bosley Mar 03 '16 at 09:39
  • Hi @hsluoyz I sent the solution files to you last week, hopefully you received them as expected. – Simon Bosley Mar 07 '16 at 13:00
  • @SimonBosley Hi. I didn't receive your mail, did you send the mail to Nmap dev list or my Gmail box? If you send to the Nmap list, maybe you need to subscribe it first, or the sending will not succeed. Or fire an issue on https://github.com/nmap/nmap/issues. – hsluoyz Mar 07 '16 at 15:56
  • I sent it to dev@nmap.org and got a receipt it sent. Check your junk mail. – Simon Bosley Mar 08 '16 at 08:30
  • 1
    @SimonBosley I'm sure that you failed to send out your mail. Check out the archive of Nmap list at: http://seclists.org/nmap-dev/2016/q1/. I searched keyword of Npcap and your name, nothing found. Why not just send your mail to: hsluoyz@gmail.com. We don't need to waste our time in dealing with the mail list failure thing. – hsluoyz Mar 08 '16 at 12:36
  • sent the download link straight to your mail this time. I expect the mailing list blocks things like WeTransfer, since they don't come from individual email addresses. – Simon Bosley Mar 08 '16 at 13:25