如下是一个获取机器eth0 网卡ip的使用示例。

cmd='''ifconfig eth0|grep "inet "|awk '{print $2}'|awk -F":" '{print $2}' '''
ret,ip = commands.getstatusoutput(cmd)
#print ip, ret
if ret != 0 :
print "get ip failed";
sys.exit(2)

posted on 2012-12-10 16:57  @且听风吟@  阅读(596)  评论(0编辑  收藏  举报