core.py 文件源码

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

项目:pyng 作者: jdowner 项目源码 文件源码
def ping(addr, size=16):
    # Open a raw socket to send the request. NB: you need to be root to have
    # permission to open a raw socket.
    sock = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP)

    # Generate a positive, random 16-bit integer to serve as the id for this
    # ping
    id = random.randint(1, 2**16 - 1)

    # Send the message and wait for the reply
    send(sock, addr, id, size)
    duration = yield from recv(sock, id)

    return duration
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号