0

我想使用 pcapdotnet 向我的免费网站发送数据包,但没有收到数据包,谁能告诉我我的错在哪里,

我的网站地址:www.infinitypower.somee.com 我使用 ping 获取 ip 地址:204.27.56.226 代码:


using System;

namespace ClientApplication
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            fillDevice();
        }

        private void btnInvoke_Click(object sender, EventArgs e)
        {
            // Take the selected adapter
            if (lsDevice.SelectedItem != null)
            {
                PcapDotNet.Core.PacketDevice selectedDevice = (PcapDotNet.Core.PacketDevice)lsDevice.SelectedItem;

                // Open the output device
                using (PcapDotNet.Core.PacketCommunicator communicator = selectedDevice.Open(100, PcapDotNet.Core.PacketDeviceOpenAttributes.Promiscuous, 1000))
                {   
                    communicator.SendPacket(BuildEthernetPacket());
                }
            }
            else
                MessageBox.Show("Select device from the list");

        }

        private void fillDevice()
        {
            lsDevice.Items.Clear();

            IList allDevices = PcapDotNet.Core.LivePacketDevice.AllLocalMachine;

            if (allDevices.Count == 0)
            {
                lsDevice.Items.Add("No interfaces found! Make sure WinPcap is installed.");
                return;
            }

            // Print the list
            for (int i = 0; i != allDevices.Count; ++i)
            {
                PcapDotNet.Core.LivePacketDevice device = allDevices[i];
                lsDevice.Items.Add(device);
            }
        }

        private PcapDotNet.Packets.Packet BuildEthernetPacket()
        {
            PcapDotNet.Packets.Ethernet.EthernetLayer ethernetLayer = new PcapDotNet.Packets.Ethernet.EthernetLayer();
            ethernetLayer.Source = new PcapDotNet.Packets.Ethernet.MacAddress("01:02:03:04:05:06");
            ethernetLayer.Destination = new PcapDotNet.Packets.Ethernet.MacAddress("01:02:03:04:05:67");
          ethernetLayer.EtherType = PcapDotNet.Packets.Ethernet.EthernetType.IpV4;

            ipV4Layer.CurrentDestination = new PcapDotNet.Packets.IpV4.IpV4Address("204.27.56.226");
                        ipV4Layer.Identification = (ushort)100;

            PcapDotNet.Packets.PayloadLayer payloadLayer = new PcapDotNet.Packets.PayloadLayer();
            payloadLayer.Data = new PcapDotNet.Packets.Datagram(System.Text.Encoding.UTF8.GetBytes(txPrayload.Text));

            PcapDotNet.Packets.PacketBuilder builder = new PcapDotNet.Packets.PacketBuilder(ethernetLayer, ipv4layer, payloadLayer);
            return builder.Build(DateTime.Now);
        }
    }
}


4

0 回答 0