标签:python
#!/usr/bin/python from subprocess import Popen,PIPE def getIfconfig(): data = Popen([‘ifconfig‘], stdout=PIPE) new_data = data.stdout.read().split(‘\n\n‘) return [i for i in new_data if i] def getIp(data): dic = {} for i in data: devname = i.split(‘\n‘)[0].split()[0] ip = i.split(‘\n‘)[1].split(‘:‘)[1].split()[0] dic[devname] = {‘ip‘:ip} return dic if __name__ == ‘__main__‘: data = getIfconfig() dic = getIp(data) print dic.items()
[root@web ~]# python ip.py //获取的ip放入到字典里。
标签:python
原文地址:http://xiaocuik.blog.51cto.com/12090846/1899648