码迷,mamicode.com
首页 > 其他好文 > 详细

收集服务器基本信息

时间:2020-06-09 17:00:57      阅读:78      评论:0      收藏:0      [点我收藏+]

标签:etl   inf   read   info   popen   snap   orm   epp   ubunt   

技术图片

#!/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)

 

收集服务器基本信息

标签:etl   inf   read   info   popen   snap   orm   epp   ubunt   

原文地址:https://www.cnblogs.com/Wshile/p/13064670.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!