コード例 #1
0
    def test_set_receive_timestamp(self):
        # Arrange
        ntp_raw = RawNTP()

        # Act
        ntp_raw.set_receive_timestamp(_TEST_BIN_64BIT)

        # Assert
        self.assertEqual(len(ntp_raw._raw), 384)
コード例 #2
0
ファイル: ntp_utils.py プロジェクト: bejohi/StegoSources
def init_ntp_pck(num_of_digits_to_fill_up: int = 12) -> NTP:
    """
    Creates a new NTP package, fills all 4 64 bit timestamps with the current time and fills up the last bits
    with random values, since they are set to 0 by Scapy
    :param num_of_digits_to_fill_up: The amount of digits to fill up.
    :return: The newly created NTP package
    """
    ntp = NTP()
    ntp.ref = ntp_time_now()
    ntp.sent = ntp_time_now()
    ntp.orig = ntp_time_now()
    ntp.recv = ntp_time_now()
    raw_ntp = RawNTP(ntp)

    f_ref = raw_ntp.reference_timestamp()
    f_trans = raw_ntp.transmit_timestamp()
    f_orig = raw_ntp.origin_timestamp()
    f_recv = raw_ntp.receive_timestamp()

    for i in range(num_of_digits_to_fill_up):
        pos = 64 - i
        f_ref = f_ref[:pos - 1] + str(random.randint(0, 1)) + f_ref[pos:]
        f_trans = f_trans[:pos - 1] + str(random.randint(0, 1)) + f_trans[pos:]
        f_orig = f_orig[:pos - 1] + str(random.randint(0, 1)) + f_orig[pos:]
        f_recv = f_recv[:pos - 1] + str(random.randint(0, 1)) + f_recv[pos:]

    assert len(f_ref) == 64
    assert len(f_trans) == 64
    assert len(f_orig) == 64
    assert len(f_recv) == 64

    raw_ntp.set_reference_timestamp(f_ref)
    raw_ntp.set_transmit_timestamp(f_trans)
    raw_ntp.set_origin_timestamp(f_orig)
    raw_ntp.set_receive_timestamp(f_recv)
    ntp = raw_ntp.ntp()
    return ntp