python 问题 急。。。

securitysun 2016-09-23 11:33:16
用python获取网卡名,格式为 eth0 eth1 eth2 eth3 怎么实现???

我这样不行os.popen("ifconfig | grep -Po '^[^ ]+'").read().strip()
...全文
651 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
raining 2016-10-15
  • 打赏
  • 举报
回复
os.popen("ifconfig | grep -Po '^\w+'").read().split()
nieoding 2016-10-13
  • 打赏
  • 举报
回复
不行是指哪里不行,输出格式不对吗

import os
map(lambda x:x.strip(':'),os.popen("ifconfig | grep -Po '^[^ ]+'").read().strip().split('\n'))
阿凯99 2016-09-29
  • 打赏
  • 举报
回复
centos6和centos7中对网卡的定义就不一样,查看的命令也不一样。还是先看看操作系统对网卡的定义吧。我看1楼用centos7、2楼用centos6
屎克螂 2016-09-27
  • 打赏
  • 举报
回复
笑看楼主。。。
夏之冰雪 2016-09-23
  • 打赏
  • 举报
回复
import netifaces as ni ni.ifaddresses('eth0') ip = ni.ifaddresses('eth0') print ip
sprawling 2016-09-23
  • 打赏
  • 举报
回复
引用 5 楼 realmardrid 的回复:
引用 3 楼 xpresslink 的回复:
os.popen('ifconfig').read().split(' ', 1)
大哥 不懂就不要回 语法编译都不过

回答问题还是希望能自己思考一下。

不要这样评价回答你问题的各位朋友。
Domenet 2016-09-23
  • 打赏
  • 举报
回复
装个psutil,分分钟各种系统信息到手,有几个网卡啊,网卡流量啊,什么都有。
securitysun 2016-09-23
  • 打赏
  • 举报
回复
引用 3 楼 xpresslink 的回复:
os.popen('ifconfig').read().split(' ', 1)
大哥 不懂就不要回 语法编译都不过
混沌鳄鱼 2016-09-23
  • 打赏
  • 举报
回复
os.popen('ifconfig').read().split(' ', 1)[0]
混沌鳄鱼 2016-09-23
  • 打赏
  • 举报
回复
os.popen('ifconfig').read().split(' ', 1)

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧