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

yipeiwu_com5年前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的Twisted框架中reactor事件管理器的用法

详解Python的Twisted框架中reactor事件管理器的用法

铺垫 在大量的实践中,似乎我们总是通过类似的方式来使用异步编程: 监听事件 事件发生执行对应的回调函数 回调完成(可能产生新的事件添加进监听队列) 回到1,监听事件...

python中的全局变量用法分析

本文实例分析了python中的全局变量用法。分享给大家供大家参考。具体分析如下: Python是一种面向对象的开发语言,在函数中使用全局变量,一般应作全局变量说明,只有在函数内经过说明的...

Pandas-Cookbook 时间戳处理方式

# -*-coding:utf-8-*- # by kevinelstri # 2017.2.17 # ----------...

python单向链表的基本实现与使用方法【定义、遍历、添加、删除、查找等】

本文实例讲述了python单向链表的基本实现与使用方法。分享给大家供大家参考,具体如下: # -*- coding:utf-8 -*- #! python3 class Node()...

Python判断Abundant Number的方法

本文实例讲述了Python判断Abundant Number的方法。分享给大家供大家参考。具体如下: Abundant Number,中文译成:盈数(又称 丰数, 过剩数abundant...