示例#1
0
        /// <summary>
        /// 数据包处理
        /// </summary>
        /// <param name="buffer">数据包</param>
        private static void onPacket(AutoCSer.Net.RawSocketListener.Buffer buffer)
        {
            using (buffer)
            {
                AutoCSer.Net.Packet.Ip ip4 = buffer.Ip;
                if (ip4.IsPacket)
                {
                    switch (ip4.Protocol)
                    {
                    case AutoCSer.Net.Packet.Ip.ProtocolEnum.Icmp:
                        AutoCSer.Net.Packet.Icmp icmp = new AutoCSer.Net.Packet.Icmp(ip4.Packet);
                        if (icmp.IsPacket)
                        {
                            Console.WriteLine(ip4.Source.toHex() + " -> " + ip4.Destination.toHex() + " " + ip4.Protocol.ToString() + " " + icmp.Type.ToString() + " " + icmp.Code.ToString());
                        }
                        else
                        {
                            Console.WriteLine("Unknown");
                        }
                        break;

                    case AutoCSer.Net.Packet.Ip.ProtocolEnum.Igmp:
                        AutoCSer.Net.Packet.Igmp igmp = new AutoCSer.Net.Packet.Igmp(ip4.Packet);
                        if (igmp.IsPacket)
                        {
                            Console.WriteLine(ip4.Source.toHex() + " -> " + ip4.Destination.toHex() + " " + ip4.Protocol.ToString());
                        }
                        else
                        {
                            Console.WriteLine("Unknown");
                        }
                        break;

                    case AutoCSer.Net.Packet.Ip.ProtocolEnum.Tcp:
                        AutoCSer.Net.Packet.Tcp tcp = new AutoCSer.Net.Packet.Tcp(ip4.Packet);
                        if (tcp.IsPacket)
                        {
                            Console.WriteLine(ip4.Source.toHex() + ":" + ((ushort)tcp.SourcePort).toHex() + " -> " + ip4.Destination.toHex() + ":" + ((ushort)tcp.DestinationPort).toHex() + " " + ip4.Protocol.ToString());
                            //if (ip4.Destination == 0xb962c48b)
                            //{
                            //    SubArray<byte> data = tcp.Packet;
                            //    Console.WriteLine("+" + System.Text.Encoding.ASCII.GetString(data.BufferArray, data.StartIndex, data.Count) + "+");
                            //}
                            //if (ip4.Source == 0xb962c48b)
                            //{
                            //    SubArray<byte> data = tcp.Packet;
                            //    Console.WriteLine("-" + System.Text.Encoding.ASCII.GetString(data.BufferArray, data.StartIndex, data.Count) + "-");
                            //}
                        }
                        else
                        {
                            Console.WriteLine("Unknown");
                        }
                        break;

                    case AutoCSer.Net.Packet.Ip.ProtocolEnum.Udp:
                        AutoCSer.Net.Packet.Udp udp = new AutoCSer.Net.Packet.Udp(ip4.Packet);
                        if (udp.IsPacket)
                        {
                            Console.WriteLine(ip4.Source.toHex() + ":" + ((ushort)udp.SourcePort).toHex() + " -> " + ip4.Destination.toHex() + ":" + ((ushort)udp.DestinationPort).toHex() + " " + ip4.Protocol.ToString());
                        }
                        else
                        {
                            Console.WriteLine("Unknown");
                        }
                        break;

                    default:
                        Console.WriteLine(ip4.Source.toHex() + " -> " + ip4.Destination.toHex() + " " + ip4.Protocol.ToString());
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("Unknown");
                }
            }
        }
示例#2
0
        /// <summary>
        /// 数据包处理
        /// </summary>
        /// <param name="buffer">数据包</param>
        private static void onPacket(AutoCSer.Net.RawSocketListener.Buffer buffer)
        {
            using (buffer)
            {
                AutoCSer.Net.Packet.Ip ip4 = buffer.Ip;
                if (ip4.IsPacket)
                {
                    switch (ip4.Protocol)
                    {
                    case AutoCSer.Net.Packet.Ip.ProtocolEnum.Icmp:
                        AutoCSer.Net.Packet.Icmp icmp = new AutoCSer.Net.Packet.Icmp(ip4.Packet);
                        if (icmp.IsPacket)
                        {
                            Console.WriteLine(ip4.Source.toHex() + " -> " + ip4.Destination.toHex() + " " + ip4.Protocol.ToString() + " " + icmp.Type.ToString() + " " + icmp.Code.ToString());
                        }
                        else
                        {
                            Console.WriteLine("Unknown");
                        }
                        break;

                    case AutoCSer.Net.Packet.Ip.ProtocolEnum.Igmp:
                        AutoCSer.Net.Packet.Igmp igmp = new AutoCSer.Net.Packet.Igmp(ip4.Packet);
                        if (igmp.IsPacket)
                        {
                            Console.WriteLine(ip4.Source.toHex() + " -> " + ip4.Destination.toHex() + " " + ip4.Protocol.ToString());
                        }
                        else
                        {
                            Console.WriteLine("Unknown");
                        }
                        break;

                    case AutoCSer.Net.Packet.Ip.ProtocolEnum.Tcp:
                        AutoCSer.Net.Packet.Tcp tcp = new AutoCSer.Net.Packet.Tcp(ip4.Packet);
                        if (tcp.IsPacket)
                        {
                            Console.WriteLine(ip4.Source.toHex() + ":" + ((ushort)tcp.SourcePort).toHex() + " -> " + ip4.Destination.toHex() + ":" + ((ushort)tcp.DestinationPort).toHex() + " " + ip4.Protocol.ToString());
                        }
                        else
                        {
                            Console.WriteLine("Unknown");
                        }
                        break;

                    case AutoCSer.Net.Packet.Ip.ProtocolEnum.Udp:
                        AutoCSer.Net.Packet.Udp udp = new AutoCSer.Net.Packet.Udp(ip4.Packet);
                        if (udp.IsPacket)
                        {
                            Console.WriteLine(ip4.Source.toHex() + ":" + ((ushort)udp.SourcePort).toHex() + " -> " + ip4.Destination.toHex() + ":" + ((ushort)udp.DestinationPort).toHex() + " " + ip4.Protocol.ToString());
                        }
                        else
                        {
                            Console.WriteLine("Unknown");
                        }
                        break;

                    default:
                        Console.WriteLine(ip4.Source.toHex() + " -> " + ip4.Destination.toHex() + " " + ip4.Protocol.ToString());
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("Unknown");
                }
            }
        }