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=(',',':'))
05-04 05:17