python获取本机mac地址和ip地址的方法

yipeiwu_com6年前Python基础

本文实例讲述了python获取本机mac地址和ip地址的方法。分享给大家供大家参考。具体如下:

import sys, socket
def getipaddrs(hostname):
  result = socket.getaddrinfo(hostname,None,0,socket.SOCK_STREAM)
  return [x[4][0] for x in result]
# the name of the local machine
hostname = socket.gethostname()
try:
  print "IP addresses:", ", ".join(getipaddrs(hostname))
except socket.gaierror, e:
  print "Couldn't not get IP addresses:", e

希望本文所述对大家的Python程序设计有所帮助。

相关文章

基于Python 装饰器装饰类中的方法实例

基于Python 装饰器装饰类中的方法实例

title: Python 装饰器装饰类中的方法 comments: true date: 2017-04-17 20:44:31 tags: ['Python', 'Decorate'...

python opencv图片编码为h264文件的实例

python部分 #!/usr/bin/env Python # coding=utf-8 from ctypes import * from PyQt5.QtCore impo...

Python实现个人微信号自动监控告警的示例

Python实现个人微信号自动监控告警的示例

wechat_sender 是基于 wxpy 和 tornado 实现的一个可以将你的网站、爬虫、脚本等其他应用中各种消息 (日志、报警、运行结果等) 发送到微信的工具。 运行环境 Py...

python下10个简单实例代码

注意:我用的python2.7,大家如果用Python3.0以上的版本,请记得在print()函数哦!如果因为版本问题评论的,不做回复哦!!! 1.题目:有1、2、3、4个数字,能组成多...

python实现按长宽比缩放图片

使用python按图片固定长宽比缩放图片到指定图片大小,空白部分填充为黑色。 代码 # -*- coding: utf-8 -*- from PIL import Image c...