Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
获取网卡IP地址列表(Linux下python实现)
#! /usr/bin/python
'''
CentOS 6.2 + Python 2.6
'''
def getIpList():
import os
ipList = []
var = os.popen('ifconfig').read().split("\n\n")
for item in var:
#print item
symble1 = "inet addr:"
pos1 = item.find(symble1)
if pos1 >= 0:
#print "find it : ",pos1
tmp1 = item[pos1+len(symble1):]
ipList.append(tmp1[:tmp1.find(" ")])
return ipList
print getIpList()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment