03_02_ping_remote_host.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:011_python_network_programming_cookbook_demo 作者: jerry-0824 项目源码 文件源码
def send_ping(self, sock, ID):
    """
    Send ping to the target host
    """
    target_addr = socket.gethostbyname(self.target_host)

    my_checksum = 0

    # Create a dummy heder with a 0 checksum.
    header = struct.pack("bbHHh", ICMP_ECHO_REQUEST, 0, my_checksum, ID, 1)
    bytes_In_double = struct.calcsize("d")
    data = (192 - bytes_In_double) * "Q"
    data = struct.pack("d", time.time()) + data

    # Get the Checksum on the data and the dummy header.
    my_checksum = self.do_checksum(header + data)
    header = struct.pack( "bbHHh", ICMP_ECHO_REQUEST, 0, socket.htons(my_checksum), ID, 1 )
    packet = header + data
    sock.sendto(packet, (target_addr, 1))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号