Exemplo n.º 1
0
        static void Main(string[] args)
        {
            try
            {
                //parse args, and put them into the Param object
                Param param = new Param(args);

                //pick the right adapter depending on the arg, null is returned if it couldn't decide
                ICaptureDevice dev = Utility.PickDevice(param);

                //update the source mac and ip addresses depending on the device that was picked
                //default values are placed if device was null
                param.UpdateDevInfo(dev);

                //actually create the packet
                Packet packet = PacketFactory.CreatePacket(param);

                Console.WriteLine("Sending the following packet:");
                Console.WriteLine(packet.ToString());
                byte[] packetBytes = packet.Bytes;

                //if no specific adapter was picked, send to every adapters, else just send it to that adapter
                if (dev == null)
                {
                    foreach (ICaptureDevice tempDev in CaptureDeviceList.Instance)
                    {
                        Console.WriteLine("-- Seending Packet to: " + Utility.GetFriendlyName(tempDev));
                        tempDev.Open();
                        tempDev.SendPacket(packetBytes);
                        Console.WriteLine("-- Packet sent successfuly.");
                        tempDev.Close();
                    }
                }
                else
                {
                    Console.WriteLine("-- Seending Packet to: " + Utility.GetFriendlyName(dev));
                    dev.Open();
                    // Send the packet out the network device
                    dev.SendPacket(packetBytes);
                    Console.WriteLine("-- Packet sent successfuly.");
                    dev.Close();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Caught an exception");
                Console.WriteLine("Message   : " + e.Message);
                Console.WriteLine("StackTrace: " + e.StackTrace);
            }
        }