收集服务器基本信息
Posted Wshile
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了收集服务器基本信息相关的知识,希望对你有一定的参考价值。
#!/usr/bin/python # coding: utf-8 import re, os DiamondPath = "cat /root/diamond-v1.100.0010-SNAPSHOT/diamond.yaml" user = "ubuntu" keyPath = "1.key" sshCmd = "ssh -i {key} ubuntu@{ip} sudo " PortDict = {} result = re.findall("- ip:[ \\t]*(.*)", os.popen(DiamondPath).read()) grepPort = "|grep \\\'{port}\\\'" newShell = "netstat -tnlp| grep -v \'Program\'" for ip in result: set01 = set() Ip = sshCmd.format(key=keyPath,ip=ip) print("*************" + ip + "*************") PortNetstat = Ip + newShell PortGrep = Ip + newShell + grepPort ServiceNam = re.findall(".*/(.*)", os.popen(PortNetstat).read().strip()) for i in ServiceNam: set01.add(i.strip()) setList = list(set01) for name in range(len(setList)): PortCmd = PortGrep.format(port=setList[name]) PortResult = list(set(re.findall(".*:(\\d+)", os.popen(PortCmd).read()))) PortDict[setList[name]] = PortResult for k, v in PortDict.items(): print(k, v)
以上是关于收集服务器基本信息的主要内容,如果未能解决你的问题,请参考以下文章