コード例 #1
0
ファイル: PacketDispatcher.cs プロジェクト: wgwjifeng/fiddly
        private void IntervalSender()
        {
            DebugInformation.WriteLine("[PD] Interval sender started.");

            // initial sleep (give some time for responses to network discovery packets - ARP replies)
            Thread.Sleep(300 * (32 - iface.CIDR));

            var routingTable = IPv4Router.Instance.GetRoutingTable();

            // set static ARP entry for current gateway
            if (routingTable.ContainsKey(iface.IPv4Gateway))
            {
                DebugInformation.WriteLine("[ARP] set static entry for gateway - " + routingTable[iface.IPv4Gateway]);
                iface.SetStaticARPGateway(routingTable[iface.IPv4Gateway]);
            }
            // we don't have our gateway's MAC address - print an error
            else
            {
                DebugInformation.WriteLine("[ERR] unable to resolve gateway's MAC address");
                DebugInformation.WriteLine("[PD] Interval sender stopped.");

                StatusInformation.ChangeStatus("Status: traffic fiddler encountered an error (see debug information)!", false);

                return;
            }

            // start main loop for sending packets from "GetPacketQueue"
            while (started)
            {
                Thread.Sleep(1250);

                if (!started)
                {
                    break;
                }

                Thread.Sleep(1250);

                if (!started)
                {
                    break;
                }

                foreach (var sender in packetSenders)
                {
                    var sendQueue = sender.GetPacketQueue();

                    sendQueue.TransmitAll(iface.PcapDevice);
                }
            }

            // send packets from "GetPacketQueueOnClose" for each sender (e.g. re-ARP poisoned targets)
            foreach (var sender in packetSenders)
            {
                var sendQueue = sender.GetPacketQueueOnClose();

                sendQueue.TransmitAll(iface.PcapDevice);
            }

            // delete static ARP entry for gateway's address
            iface.DeleteStaticARP(iface.IPv4Gateway);

            DebugInformation.WriteLine("[PD] Interval sender stopped.");
        }