美文网首页
2023-11-06

2023-11-06

作者: Poisson_Lee | 来源:发表于2023-11-05 09:31 被阅读0次

get_mac_id.py

import uuid
import psutil


def get_device_any_mac():
    address  = hex(uuid.getnode())[2:]
    #print(address)
    mac_str = "-".join(address[i:i+2] for i in range(0, len(address), 2))
    return mac_str.upper()


def get_device_all_mac():
    mac_q = []
    for k, v in psutil.net_if_addrs().items():
        for item in v:
            address = item[1]
            if "-" in address and len(address)==17:
                mac_q.append(address.upper())
    return mac_q


if __name__=="__main__":
    uuid_mac = get_device_any_mac()
    print(uuid_mac)
    all_mac = get_device_all_mac()
    print(all_mac)

key_exp_manager.py

import ntplib
import time
import datetime
import math


DAY_SEC_NUM = 24*3600

def get_sec_time_from_network():
    ntpClient = ntplib.NTPClient()
    response = ntpClient.request("pool.ntp.org")    # result is float repr
    return int(response.tx_time)


def get_sec_time_from_set(year=2023, mon=10, day=3):
    date_time = datetime.datetime(year, mon, day, 0, 0, 0)
    return int(date_time.timestamp())


def get_day_intervals(ref_sec_time=0, cmp_sec_time=0):
    return math.floor((cmp_sec_time - ref_sec_time)/DAY_SEC_NUM)


def key_is_valid(day_interval=0, exp_date=30):
    return (day_interval <= exp_date)
    

if __name__=="__main__":
    network_time = get_sec_time_from_network()
    display_network_time = time.localtime(network_time)
    print(network_time)
    print(display_network_time)
    set_sec_time = get_sec_time_from_set(year=2023, mon=10, day=1)
    used_days = get_day_intervals(set_sec_time, network_time)
    print(used_days)
    key_legal_or_not = key_is_valid(used_days)
    print(key_legal_or_not)

encrypt_and_decrypt.py

import uuid
import psutil


def get_device_any_mac():
    address  = hex(uuid.getnode())[2:]
    #print(address)
    mac_str = "-".join(address[i:i+2] for i in range(0, len(address), 2))
    return mac_str.upper()


def get_device_all_mac():
    mac_q = []
    for k, v in psutil.net_if_addrs().items():
        for item in v:
            address = item[1]
            if "-" in address and len(address)==17:
                mac_q.append(address.upper())
    return mac_q


if __name__=="__main__":
    uuid_mac = get_device_any_mac()
    print(uuid_mac)
    all_mac = get_device_all_mac()
    print(all_mac)

相关文章

  • 2023-11-06

  • 2023-11-06少爷和丫鬟

    最近在看《京华烟云》,现在看到了少爷体仁和丫鬟银屏的部分,心中突然有些感慨。 多情少爷x美貌丫鬟的故事并不罕见,比...

网友评论

      本文标题:2023-11-06

      本文链接:https://www.haomeiwen.com/subject/xuyzidtx.html