使用ping确定远程计算机的操作系统

时间:2018-11-21 06:58:11

标签: python python-3.x sockets operating-system ping

我正在尝试找出如何查找远程计算机的操作系统 正在使用ping方法运行。

我不知道如何获取TTL编号并查看列表以查找其使用的操作系统。

SELECT salary FROM Employee ORDER BY salary DESC LIMIT 1,1

1 个答案:

答案 0 :(得分:1)

在python中有一个ping的实现:

https://gist.github.com/chidea/955cea841e5c76a7e5ee8aa02234409d

查看receive_ping函数。 TTL是接收到的数据包的第9个字节(索引8)。因此,我在该函数中打印了TTL:

def receive_ping(my_socket, packet_id, time_sent, timeout):
# Receive the ping from the socket.
time_left = timeout
while True:
    started_select = time.time()
    ready = select.select([my_socket], [], [], time_left)
    how_long_in_select = time.time() - started_select
    if ready[0] == []: # Timeout
        return
    time_received = time.time()
    rec_packet, addr = my_socket.recvfrom(1024)
    print ("TTL:", rec_packet[8]) # IT PRINT THE TTL! HAVE A NICE DAY :)
    icmp_header = rec_packet[20:28]
    type, code, checksum, p_id, sequence = struct.unpack(
        'bbHHh', icmp_header)
    if p_id == packet_id:
        return time_received - time_sent
    time_left -= time_received - time_sent
    if time_left <= 0:
        return