批量添加监听端口
2019-07-16 16:57 divl 阅读(744) 评论(0) 编辑 收藏 举报利用discovery 批量添加端口;
1. 端口扫描脚本
#!/usr/bin/env python #coding:utf-8 import os,json port_white_list=["9200","9092","11111","10050","22"] port_dict={"data":None}; port_list=[] cmd='''/usr/sbin/ss -anlp | grep tcp | awk '{print $5}' | awk -F':' '{if($NF ~/^[0-9]*$/) print $NF}' | sort | uniq 2>/dev/null''' local_port=os.popen(cmd).readlines() for port_tmp in local_port: port=port_tmp.replace("\n","") if port in port_white_list: port_list_tmp={} port_list_tmp["{#TCP_PORT}"]=port port_list.append(port_list_tmp) port_dict["data"]=port_list jsonStr=json.dumps(port_dict,sort_keys=True,indent=4) print jsonStr
2.添加key
3. 测试key
4. 在自定义模板中添加discovery.