Created
November 12, 2012 05:38
-
-
Save mike-zhang/4057685 to your computer and use it in GitHub Desktop.
获取网卡IP地址列表(Linux下python实现)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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