Esempio n. 1
0
 private void btn_connect_Click(object sender, EventArgs e)
 {
     if (local_ip.Length != 0)
     {
         string[] info = txt_address.Text.Split(':');
         XCOM_Core.Initialize(local_ip, info[0], Convert.ToInt32(info[1]));
     }
     else
     {
         MessageBox.Show("Not Connected to network!");
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Prints the time, length, src ip, src port, dst ip and dst port
        /// for each TCP/IP packet received on the network
        /// </summary>
        private static void device_OnPacketArrival(object sender, CaptureEventArgs e)
        {
            var time = e.Packet.Timeval.Date;
            var len  = e.Packet.Data.Length;

            var      packet   = PacketDotNet.Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data);
            String   bytes    = UTF8Encoding.UTF8.GetString(packet.Bytes);
            Packet   p        = new Packet();
            IpPacket ipPacket = (IpPacket)packet.Extract(typeof(IpPacket));

            if (ipPacket != null)
            {
                p.IpPacket = Utils.CreateIPpacket(new MJsniffer.IPHeader(ipPacket.Header, ipPacket.Header.Length));
                p.Timespan = time.ToString();
                if (ipPacket.PayloadPacket != null)
                {
                    TcpPacket tcpPacket = (TcpPacket)ipPacket.PayloadPacket.Extract(typeof(TcpPacket));
                    if (tcpPacket != null)
                    {
                        p.Type      = "TCP";
                        p.TcpPacket = Utils.CreateTCPpacket(new MJsniffer.TCPHeader(tcpPacket.Header, tcpPacket.Header.Length));
                        XCOM_Core.AddPacket(p, tcpPacket.PayloadData);
                    }
                    else
                    {
                        UdpPacket udpPacket = (UdpPacket)ipPacket.PayloadPacket.Extract(typeof(UdpPacket));
                        if (udpPacket != null)
                        {
                            p.Type      = "UDP";
                            p.UdpPacket = Utils.CreateUDPpacket(new MJsniffer.UDPHeader(udpPacket.Header, udpPacket.Header.Length));
                            XCOM_Core.AddPacket(p, udpPacket.PayloadData);
                        }
                    }
                }
            }

            //if (tcpPacket != null)
            //{
            //    var tcpPacket = (IpPacket)tcpPacket.ParentPacket;
            //    System.Net.IPAddress srcIp = ipPacket.SourceAddress;
            //    System.Net.IPAddress dstIp = ipPacket.DestinationAddress;
            //    int srcPort = tcpPacket.SourcePort;
            //    int dstPort = tcpPacket.DestinationPort;

            //    Console.WriteLine("{0}:{1}:{2},{3} Len={4} {5}:{6} -> {7}:{8}",
            //        time.Hour, time.Minute, time.Second, time.Millisecond, len,
            //        srcIp, srcPort, dstIp, dstPort);
            //}
        }