Skip to content

Instantly share code, notes, and snippets.

@mike-zhang
Created November 12, 2012 05:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mike-zhang/4057685 to your computer and use it in GitHub Desktop.
Save mike-zhang/4057685 to your computer and use it in GitHub Desktop.
获取网卡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