小编Sjo*_*elt的帖子

如何在python中构造ICMP数据包

为了学习,我目前正在尝试创建一个简单的python porgram来向某个设备发送ICMP ping数据包.为了开始,我查看了python模块的源代码Pyping:https://github.com/Akhavi/pyping/blob/master/pyping/core.py

我试图了解发送和构建数据包时发生的所有情况,但是我已经设法卡在代码的一部分上,似乎无法弄清楚它的功能和用途究竟是什么.我一直在研究ICMP数据包,我知道它们包含类型代码校验和和数据 现在困扰我的代码是:

    self.own_id = os.getpid() & 0xFFFF

    header = struct.pack(
        "!BBHHH", ICMP_ECHO, 0, checksum, self.own_id, self.seq_number
    )

    padBytes = []
    startVal = 0x42
    for i in range(startVal, startVal + (self.packet_size)):
        padBytes += [(i & 0xff)]  # Keep chars in the 0-255 range
    data = bytes(padBytes)
Run Code Online (Sandbox Code Playgroud)

我的问题是:

  1. 将self.own_id和self.seq_number添加到标头有什么用?
  2. 在for循环中计算的是什么,为什么它具有特定的起始值0x42?

我是网络新手,任何帮助都会非常感激.

python networking byte icmp

3
推荐指数
1
解决办法
8141
查看次数

jQuery .get not working

每当.information单击该元素时,我都会运行以下代码.我想在单击时将aboutMe.html文档添加到#text元素.information:

$(".information").click( function() {
    $.get("aboutMe.html"), function(data){
        $("#text").html(data);
}});
Run Code Online (Sandbox Code Playgroud)

由于某种原因,.information单击时文档不会添加到页面中.

javascript jquery get

1
推荐指数
1
解决办法
8109
查看次数

Python将非数字字符串存储为数字

我目前正在尝试找到一种将任何类型的文本转换为数字的方法,以便以后可以将其转换回文本。所以像这样:

text = "some string"
number = somefunction(text)

text = someotherfunction(number)
print(text) #output "some string"
Run Code Online (Sandbox Code Playgroud)

python

1
推荐指数
1
解决办法
2841
查看次数

标签 统计

python ×2

byte ×1

get ×1

icmp ×1

javascript ×1

jquery ×1

networking ×1