python获取本机mac地址和ip地址的方法
时间:2021-11-29 16:24 作者:admin
本文实例讲述了python/' target='_blank'>python获取本机mac地址和ip地址的方法。分享给大家供大家参考。具体如下:
import sys, socketdef getipaddrs(hostname): result = socket.getaddrinfo(hostname,None,0,socket.SOCK_STREAM) return [x[4][0] for x in result]# the name of the local machinehostname = socket.gethostname()try: print "IP addresses:", ", ".join(getipaddrs(hostname))except socket.gaierror, e: print "Couldn't not get IP addresses:", e
希望本文所述对大家的Python程序设计有所帮助。
(责任编辑:admin)