为什么我无法发送该IP包? [英] Why can't I send this IP packet?

查看:201
本文介绍了为什么我无法发送该IP包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用C#发送一个IP数据包。

I'm trying to send an IP packet using c#.

    destAddress = IPAddress.Parse("192.168.0.198"),
    destPort = 80;

    // Create a raw socket to send this packet
    rawSocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);

    // Bind the socket to the interface specified
    IPEndPoint iep = new IPEndPoint(IPAddress.Parse("192.168.0.140"),0);
    rawSocket.Bind(iep);

    // Set the HeaderIncluded option since we include the IP header
    rawSocket.SetSocketOption( socketLevel, SocketOptionName.HeaderIncluded, 1 );

    // Send the packet!
    int rc = rawSocket.SendTo(builtPacket, new IPEndPoint(destAddress, destPort));
    Console.WriteLine("sent {0} bytes to {1}", rc, destAddress.ToString());



builtPacket的含量如下所示。它包含一个TCP SYN数据包的IP报文(这就是我想我反正创建)。

The content of builtPacket is shown below. It's an IP packet containing a TCP SYN packet (That's what I think I created anyway).

45 00 00 28 00 00 00 00 02 06 36 6E C0 A8 00 8C

45 00 00 28 00 00 00 00 02 06 36 6E C0 A8 00 8C

C0 A8 00 C6 14 1E 00 50 00 00 00 00 00 00 00 00

C0 A8 00 C6 14 1E 00 50 00 00 00 00 00 00 00 00

05 02 FF FF E6 4F 00 00

05 02 FF FF E6 4F 00 00

输出是:

sent 40 bytes to 192.168.0.198

问题是我没有看到在Wireshark的跟踪任何东西。这就像该数据没有得到足够远下来栈Wireshark来看看吗?如果我用浏览器连接到192.168.0.198,Wireshark的显示所有的数据包,但说明不了什么,当我尝试使用上面的代码和数据发送一个数据包。

The problem is I don't see anything in the Wireshark trace. It's like the data is not getting far enough down the stack for Wireshark to see it? If I use a browser to connect to 192.168.0.198, Wireshark shows all the packets, but shows nothing when I try to send a packet using the above code and data.

我的配置:


  • 我正在运行的管理所以它的没有权限问题。

  • I am running as admin so it's not a permissions problem.

Windows7的(在一个虚拟机未运行)

Windows7 ( Not running in a VM)

仅用于无线连接(IP配置报告其IP作为192.168.0.140)

Wireless connection only (IP config reports its IP as 192.168.0.140)

我在做什么错了?

我敢肯定,奥卡姆剃刀适用于这里,但是我一直在寻找这个几个小时,不能找出什么是错的。

I'm sure Occam's Razor applies here, but I've been looking at this for hours and can't figure out what's wrong.

推荐答案

这个问题,的备份通过MSDN 声称,Windows无法(XP SP 2通过7)允许使用原始套接字的TCP数据传输。

This question, backed up by MSDN, claims that Windows no longer (XP SP 2 through 7) allows transmission of TCP data using raw sockets.

这篇关于为什么我无法发送该IP包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆