关于python数列的交集/usr/bin/pythonimport osimport jsonimport timedata = {}tcp_list = []port_list = []ports_list = []a = []b = []command = 'netstat -ano -p tcp| find "LISTENING" 'lines = os.popen(command).readlines()for line in lines:port = li
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/18 00:48:01
关于python数列的交集/usr/bin/pythonimport osimport jsonimport timedata = {}tcp_list = []port_list = []ports_list = []a = []b = []command = 'netstat -ano -p tcp| find "LISTENING" 'lines = os.popen(command).readlines()for line in lines:port = li
关于python数列的交集
/usr/bin/python
import os
import json
import time
data = {}
tcp_list = []
port_list = []
ports_list = []
a = []
b = []
command = 'netstat -ano -p tcp| find "LISTENING" '
lines = os.popen(command).readlines()
for line in lines:
port = line.split()[1].split(':')[1]
port_list.append(port)
a = set(port_list)
time.sleep(0.1)
command = 'netstat -ano -p tcp| find "LISTENING" '
lines = os.popen(command).readlines()
for line in lines:
port = line.split()[1].split(':')[1]
ports_list.append(port)
b = set(ports_list)
print set(a & b)
for port in list(set(a & b)):
port_dict = {}
port_dict['{#TCP_PORT}'] = port
tcp_list.append(port_dict)
data['data'] = tcp_list
jsonStr = json.dumps(data,sort_keys=True,indent=4)
print jsonStr
照理说port_list和ports_list获取的数据都是一样的,用set获取连个数列的交集应该没输出才对的.
不用了,用错参数.
关于python数列的交集/usr/bin/pythonimport osimport jsonimport timedata = {}tcp_list = []port_list = []ports_list = []a = []b = []command = 'netstat -ano -p tcp| find "LISTENING" 'lines = os.popen(command).readlines()for line in lines:port = li
混份儿 题主机智