python 自动发现Java端口
#!/usr/bin/env python
#encoding: utf8
import subprocess
try:
import json
except ImportError:
import simplejson as json
command = "netstat -tpln | grep -v '127.0.0.1' | awk -F '[ :]+' '/java/ && / / {print $5}'"
p = subprocess.Popen(command,shell=True,stdout=subprocess.PIPE)
port_list = p.stdout.read().split('\n')
port = []
for i in port_list:
if len(i) != 0:
port += [{'{#JAVA_PORT}':i}]
print json.dumps({'data':port},sort_keys=True,indent=4,separators=(',',':'))
原文地址:https://www.cnblogs.com/Mrhuangrui/p/9259704.html
时间: 2024-11-10 00:24:38