python获取本机mac地址和ip地址的方法
作者:重负在身 时间:2023-02-25 00:38:16
本文实例讲述了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,mac地址,ip地址
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python3利用Dlib19.7实现人脸68个特征点标定
2021-05-05 19:13:06
![](https://img.aspxhome.com/file/2023/4/76034_0s.jpg)
phpcms手机内容页面添加上一篇和下一篇
2024-05-11 09:54:05
使用有趣的自定义标记布局页面
2012-07-12 01:29:03
ASP经常用到的函数
2009-07-06 13:00:00
Mysql实现定时清空一张表的旧数据并保留几条数据(推荐)
2024-01-17 06:38:11
TensorFlow神经网络创建多层感知机MNIST数据集
2022-03-29 20:09:19
Python 程序报错崩溃后如何倒回到崩溃的位置(推荐)
2021-01-08 16:14:34
![](https://img.aspxhome.com/file/2023/1/83991_0s.jpg)
Python对列表去重的多种方法(四种方法)
2023-03-18 23:38:19
Python中 join() 函数的使用示例讲解
2023-03-29 02:32:25
Sql Server使用cursor处理重复数据过程详解
2024-01-27 09:01:35
python 实现 redis 数据库的操作
2024-01-16 07:46:08
Python2.7环境Flask框架安装简明教程【已测试】
2023-12-17 11:59:42
![](https://img.aspxhome.com/file/2023/7/87707_0s.png)
Python中的推导式使用详解
2022-10-30 00:42:49
Python实现葵花8号卫星数据自动下载实例
2021-09-26 13:40:25
使用Python制作一个打字训练小工具
2021-10-19 20:23:12
![](https://img.aspxhome.com/file/2023/7/120317_0s.jpg)
Perl合并文本的一段实例代码
2023-10-31 05:05:23
安装SQL Server2019详细教程(推荐!)
2024-01-22 18:23:11
![](https://img.aspxhome.com/file/2023/7/88257_0s.png)
Mysql删除重复数据并且只保留一条(附实例!)
2024-01-27 04:48:27
![](https://img.aspxhome.com/file/2023/8/122348_0s.png)
详解Python中的分组函数groupby和itertools)
2022-08-30 15:03:18
举例详解Python中的split()函数的使用方法
2021-06-23 07:26:49