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)