【问题标题】:Using WireShark to check WCF TCP Server and Client traffic on localhost使用 WireShark 检查本地主机上的 WCF TCP 服务器和客户端流量
【发布时间】:2016-06-08 13:34:41
【问题描述】:

我使用 WCF 在 Visual Studio 中创建了一个简单的 TCP 客户端和 TCP 服务器。我在服务器上有一个简单的操作,它接收一个整数,递增它并将它发回。它按预期工作。

我想使用 Wireshark 来监控在 localhost 上运行的客户端和服务器之间的流量。显然,这在 Windows 上安装 Wireshark 标准是不可能的,因为它无法监控环回适配器。有一个名为 Npcap 的库旨在解决这个问题,所以我安装了这个:

Npcap on GitHub

当我运行 Wireshark 并选择捕获的

Npcap 环回适配器

我没有看到任何 TCP 流量(仅某些 UDP 和 DHCP)。我想知道我希望看到什么?

服务器的 C# 代码在这里(我以编程方式创建它,以便您可以看到所有详细信息,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();
        }
    }
}

【问题讨论】:

    标签: wcf tcp wireshark npcap


    【解决方案1】:

    我是 Npcap 的作者。首先感谢您的报告!

    首先我想提一下,获得有关 Npcap 帮助的最佳方式是使用邮件列表:dev@nmap.org 或在https://github.com/nmap/nmap/issues 提出问题。我每天都检查那些地方。我主要使用Stackoverflow 来提问,但很少搜索和回答有关 Npcap 的问题。

    我不是 C# 方面的专家。我在我的 VS2015 中创建了一个 WCF Service Application 项目。将您的代码复制到我的Service1.svc.cs。将其构建为WcfService1.dll。但是不知道怎么用?

    您介意提供所有服务器和客户端代码(包括解决方案文件)吗?所以我可以用它们来测试 Npcap(不需要掌握 C# 和 WCF 的知识)。您可以压缩代码并将压缩包附在邮件中到 dev@nmap.org。我会回复的。谢谢!

    【讨论】:

    • 非常感谢您回答我的问题,我没想到作者 :-)。我会把它拉上拉链,然后通过 WeTransfer 发送出去,希望是今天。
    • 嗨@hsluoyz 我上周将解决方案文件发送给您,希望您按预期收到。
    • @SimonBosley 嗨。我没有收到你的邮件,你是把邮件发到 Nmap 开发者列表还是我的 Gmail 邮箱?如果发送到 Nmap 列表,可能需要先订阅,否则发送不成功。或在github.com/nmap/nmap/issues 上提出问题。
    • 我将它发送到 dev@nmap.org 并收到了它发送的收据。检查您的垃圾邮件。
    • @SimonBosley 我确定您未能发送邮件。查看 Nmap 列表的存档:seclists.org/nmap-dev/2016/q1。我搜索了 Npcap 的关键字和你的名字,没有找到。为什么不直接将您的邮件发送到:hsluoyz@gmail.com。我们不需要浪费时间来处理邮件列表失败的事情。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-29
    • 2015-04-15
    • 2021-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多