Python获取本地mac地址、主机名、IP地址
生活随笔
收集整理的这篇文章主要介绍了
Python获取本地mac地址、主机名、IP地址
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
1 在windows系统,命令行输入
ipconfig /all
此处获得mac地址。
2 在Python中获取mac地址
import uuid mac = uuid.UUID( int=uuid.getnode() ).hex[-12:] print(mac)uuid.getnode()得到节点唯一的整数号,也就是mac地址的整数形式。
即获得了mac地址的字节串。为了获得“:”间隔的mac地址格式,可以用语句:
MAC= ":".join( [ mac[e:e+2] for e in range(0,11,2) ] )3 获取主机名称、IP地址
import socket# 获取主机名 hostname = socket.gethostname() # 获取IP ip = socket.gethostbyname(hostname)print("主机名:",hostname) print("IP:",ip)总结
以上是生活随笔为你收集整理的Python获取本地mac地址、主机名、IP地址的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: Python的setuptools详解【
- 下一篇: Python概念:生成唯一性序号uuid