如何在两个IP之间传输数据?

时间:2014-09-18 09:10:21

标签: c# packet

首先抱歉我的英语 我使用以下代码来数据包嗅探器

public partial class Form1 : Form
{
    Byte[] data=new Byte[10000];
    Socket sc;
    String backup;
    public Form1()
    {
            connection(IPAddress.Parse("myip"));

    }
    public void connection(IPAddress ip)
    {
        sc = new Socket(AddressFamily.InterNetwork,SocketType.Raw,ProtocolType.IP);
        sc.Bind(new IPEndPoint(ip,0));
        sc.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, true);
        sc.IOControl(IOControlCode.ReceiveAll, new Byte[4] { 1, 0, 0, 0 }, new Byte[4] { 1, 0, 0, 0 });
        sc.BeginReceive(data, 0, data.Length, SocketFlags.None, new AsyncCallback(scr), null);
    }

    private void scr(IAsyncResult ar)
    {
        sc.EndReceive(ar);
        String bt = Encoding.ASCII.GetString(data);
            richTextBox1.Invoke(new Action(() => backup = richTextBox1.Text));
            richTextBox1.Invoke(new Action(() => richTextBox1.Text = backup + "\n\n" +
                new IPAddress(BitConverter.ToUInt32(data, 16)).ToString() + ":" + ((ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, 22))).ToString() +
                "\n" +
                new IPAddress(BitConverter.ToUInt32(data, 12)).ToString() + ":" + ((ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, 20))).ToString()));
            data = new Byte[10000];
            sc.BeginReceive(data, 0, data.Length, SocketFlags.None, new AsyncCallback(scr), null);
    }

}

但是如何在两个ips(我的ip和目标ip)之间传输数据并对其进行解码 或者我可以这样做吗?

0 个答案:

没有答案