重播UDP数据包捕获

时间:2012-01-25 17:13:57

标签: c# udp packet-capture

我有一个UDP数据包捕获,我使用网络N1上的wireshark捕获。此捕获包含从​​IP地址IP1上的端口4000到IP地址IP2上的端口4000的数据包。

我现在正在网络N2上使用Colaso​​ft Packet Player重播这些数据包,将数据包从IP地址IP3发送到IP地址P4。

由于我正在重播数据包,我认为它们将在端口4000上发送和接收。这已通过使用wireshark捕获重播数据包得到确认。

但是,我无法在使用C#编写的UDP服务器中看到任何这些数据包(由于公司的机密性原因,我无法在此处发布)。为了消除我的代码方面的任何错误怀疑,我从在线示例下载了以下代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;

// SERVER.CS
// This is a simple UDP server that receives a UDP datagram containing a random word to a server on the local computer
// usage server.exe [PORT], where [PORT] is the sever UDP port number of the local PC

namespace UDPLocalServer
{
    class ProgramServer
    {
        static void Main(string[] args)
        {
                if (args.Length != 1)
            {
                Console.WriteLine("USAGE: client.exe [PORT] [MESSAGE]");
                Environment.Exit(1);
                }

            byte[] message = new byte[128];

            String server_name         = Dns.GetHostName();             // Get the name     of the sever
            IPHostEntry server_host    = Dns.GetHostEntry(server_name); // Internet host address information
            IPAddress server_ip        = server_host.AddressList[0];    // IP address of the server
            IPEndPoint server_endpoint = new IPEndPoint(server_ip, Convert.ToInt16(args[0])); // IP and PORT pairing of the server

            // Creates an IPEndPoint to capture the identity of the client when we'll use the Socket.ReceiveFrom Method
            IPEndPoint remote_endpoint = new IPEndPoint(IPAddress.Any, 4000);   // IP and PORT pairing of the client

            Socket server_udp_socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            // Bind the Socket to the local endpoint
            server_udp_socket.Bind(server_endpoint);

            // Receive message from the remote local client
            EndPoint ep = (EndPoint)remote_endpoint;
            server_udp_socket.ReceiveFrom(message, ref ep);

            Console.WriteLine(System.Text.Encoding.Unicode.GetString(message));
            Console.WriteLine(ep.ToString());
            Console.WriteLine(message this program is not able to show me any udp communication, while wireshark is showing me incoming packets.

我真的不明白为什么会发生这种情况,我对此事表示感谢。

谢谢

0 个答案:

没有答案
相关问题