def checksum(data) -> int:
    """
    Found on: http://www.binarytides.com/raw-socket-programming-in-python-linux/. Modified to work in python 3.
    The checksum is the 16-bit ones's complement of the one's complement sum
    of the ICMP message starting with the ICMP Type (RFC 792).
    :param data: data to built checksum from.
    :return: 16-bit int checksum
    """
    s = 0
    for i in range(0, len(data), 2):
        tmp = data[i]
        if i + 1 < len(data):
            tmp += (data[i + 1] << 8)
        s += tmp
    s = (s >> 16) + (s & 0xffff)
    s += (s >> 16)
    s = ~s & 0xffff
    return s