Exemplo n.º 1
0
        static void Main(string[] args)
        {
            // create a new instance of the RawEthernet Class
            // the constructor will also open a handle to the driver
            RawEthernet rawether = new RawEthernet();

            // check to see if we got a valid handle
            if (rawether.m_bDriverOpen)
            {
                // we have a handle to the device
                Console.WriteLine("Handle to NDIS Driver: " + rawether.Handle.ToString());
            }
            else
            {
                // we don't have a handle so alert user and quit
                Console.WriteLine("ERROR: NDIS Driver could not be opened\n");
                Console.WriteLine("Press enter to exit...");
                Console.ReadLine();
                return;
            }

            // OK, now we have a handle to the driver, so let's get a list of the
            // adapters that are using that driver
            AdaptersInfo[] aiAdapters = rawether.EnumerateAdapters();
            // List the adapters so that we can choose which one we want to use
            Console.WriteLine("\nThe following adapters can be used to send packets:");
            foreach (AdaptersInfo ai in aiAdapters)
            {
                Console.WriteLine("\t" + ai.ToString());
            }
            // Ask the user to choose the index of the adapter that they want to send from
            Console.Write("\nChoose the adapter number that you want to send from: ");
            // Get the value that they type
            int adIndex = Convert.ToInt32(Console.ReadLine());


            // ok, now bind that adapter to the driver handle that we have open
            if (!rawether.BindAdapter(aiAdapters[adIndex].AdapterID))
            {
                // alert user and quit
                Console.WriteLine("ERROR: Could not bind to the adapter.\n");
                Console.WriteLine("Press enter to exit...");
                Console.ReadLine();
                return;
            }
            else
            {
                // tell the user that we are bound to the adapter
                Console.WriteLine("\nAdapter " + aiAdapters[adIndex].AdapterID +
                                  " is ready for writing...\n");
            }

            // ok, now we are ready to write a raw packet on the adapter
            // create a generic raw packet (must be at least 16 bytes long)
            byte[] packet = new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,        //destination mac
                                         0x00, 0x02, 0x3e, 0x4c, 0x49, 0xaa,        //source mac
                                         0x08, 0x00,                                //protocol
                                         0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };      //generic data

            // write the packet to the device a few times
            rawether.DoWrite(packet);
            rawether.DoWrite(packet);
            rawether.DoWrite(packet);

            // Prompt user for exit
            Console.WriteLine("\nPress enter to exit...");
            Console.ReadLine();

            // Close the drive an associated resources
            rawether.CloseDriver();
            rawether = null;
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            // create a new instance of the RawEthernet Class
            // the constructor will also open a handle to the driver
            RawEthernet rawether = new RawEthernet();

            // check to see if we got a valid handle
            if (rawether.m_bDriverOpen)
            {
                // we have a handle to the device
                Console.WriteLine("Handle to NDIS Driver: " + rawether.Handle.ToString());
            }
            else
            {
                // we don't have a handle so alert user and quit
                Console.WriteLine("ERROR: NDIS Driver could not be opened\n");
                Console.WriteLine("Press enter to exit...");
                Console.ReadLine();
                return;
            }

            // OK, now we have a handle to the driver, so let's get a list of the
            // adapters that are using that driver
            AdaptersInfo[] aiAdapters = rawether.EnumerateAdapters();
            // List the adapters so that we can choose which one we want to use
            Console.WriteLine("\nThe following adapters can be used to send packets:");
            foreach (AdaptersInfo ai in aiAdapters)
            {
                Console.WriteLine("\t" + ai.ToString());
            }
            // Ask the user to choose the index of the adapter that they want to send from
            Console.Write("\nChoose the adapter number that you want to send from: ");
            // Get the value that they type
            int adIndex = Convert.ToInt32(Console.ReadLine());

            // ok, now bind that adapter to the driver handle that we have open
            if (!rawether.BindAdapter(aiAdapters[adIndex].AdapterID))
            {
                // alert user and quit
                Console.WriteLine("ERROR: Could not bind to the adapter.\n");
                Console.WriteLine("Press enter to exit...");
                Console.ReadLine();
                return;
            }
            else
            {
                // tell the user that we are bound to the adapter
                Console.WriteLine("\nAdapter " + aiAdapters[adIndex].AdapterID +
                    " is ready for writing...\n");
            }

            // ok, now we are ready to write a raw packet on the adapter
            // create a generic raw packet (must be at least 16 bytes long)
            byte[] packet = new byte[] {0xff,0xff,0xff,0xff,0xff,0xff,  //destination mac
                                        0x00,0x02,0x3e,0x4c,0x49,0xaa,  //source mac
                                        0x08,0x00,					    //protocol
                                        0x01,0x02,0x03,0x04,0x05,0x06}; //generic data

            // write the packet to the device a few times
            rawether.DoWrite(packet);
            rawether.DoWrite(packet);
            rawether.DoWrite(packet);

            // Prompt user for exit
            Console.WriteLine("\nPress enter to exit...");
            Console.ReadLine();

            // Close the drive an associated resources
            rawether.CloseDriver();
            rawether = null;
        }