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))
03_02_ping_remote_host.py 文件源码
python
阅读 31
收藏 0
点赞 0
评论 0
评论列表
文章目录