小编Har*_*vey的帖子

无法从Python中的原始套接字发送ICMP数据包

我有一个原始的Python套接字初始化如下:

mySocket = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
mySocket.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
Run Code Online (Sandbox Code Playgroud)

我的问题是我不能从套接字发送任何数据包,我的IP头中的协议字段被指定为'1'(ICMP).如果这个字段是其他任何东西它就可以正常工作,例如包括'17'(UDP).我没有收到任何错误,数据包只是没有显示在Wireshark中,我无法在我的服务器上收到它.

我正在生成IP头,如下所示:

def getIPHeader(src, dst, proto):
    version = 4
    IHL = 5
    DSCP = 0
    ECN = 0
    totalLength = 40
    identification = 333
    flags = 0
    fragmentOffset = 0
    timeToLive = 128
    protocol = proto
    headerChecksum = 0
    sourceIP = socket.inet_aton(src)
    destIP = socket.inet_aton(dst)
    options = 0

    version_IHL = (version << 4) | IHL
    DSCP_ECN = (DSCP << 2) | ECN
    flags_fragmentOffset = (flags << 13) | fragmentOffset

    # The …
Run Code Online (Sandbox Code Playgroud)

python sockets udp wireshark

6
推荐指数
0
解决办法
1510
查看次数

检查点是否在旋转的矩形内

我知道这个问题之前曾被问过几次,我已经阅读过有关此问题的各种帖子.但是,我正在努力让这个工作.

    bool isClicked()
    {
        Vector2 origLoc = Location;
        Matrix rotationMatrix = Matrix.CreateRotationZ(-Rotation);
        Location = new Vector2(0 -(Texture.Width/2), 0 - (Texture.Height/2));
        Vector2 rotatedPoint = new Vector2(Game1.mouseState.X, Game1.mouseState.Y);
        rotatedPoint = Vector2.Transform(rotatedPoint, rotationMatrix);

        if (Game1.mouseState.LeftButton == ButtonState.Pressed &&
            rotatedPoint.X > Location.X &&
            rotatedPoint.X < Location.X + Texture.Width &&
            rotatedPoint.Y > Location.Y &&
            rotatedPoint.Y < Location.Y + Texture.Height)
        {
            Location = origLoc;
            return true;
        }
        Location = origLoc;
        return false;
    }
Run Code Online (Sandbox Code Playgroud)

c# math graphics xna geometry

4
推荐指数
2
解决办法
3870
查看次数

标签 统计

c# ×1

geometry ×1

graphics ×1

math ×1

python ×1

sockets ×1

udp ×1

wireshark ×1

xna ×1