python實現獲取電腦IP、主機名、Mac地址


import socket
import uuid

# 獲取主機名
hostname = socket.gethostname()
#獲取IP
ip = socket.gethostbyname(hostname)
# 獲取Mac地址
def get_mac_address():
    mac=uuid.UUID(int = uuid.getnode()).hex[-12:]
    return ":".join([mac[e:e+2] for e in range(0,11,2)])

# ipList = socket.gethostbyname_ex(hostname)
# print(ipList)
print("主機名:",hostname)
print("IP:",ip)
print("Mac地址:",get_mac_address())

原文鏈接:https://blog.csdn.net/lm_is_dc/article/details/80437053

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM