首页 > 编程知识 正文

elasticsearch 基本查询教程,搜索功能如何使用elasticsearch

时间:2023-05-05 05:24:55 阅读:241836 作者:4583

文章目录 注册shodan并获取API安装shodan注册censys并获取API安装censys用censys查询可用elasticsearch资源
记得以前我在elastic社区分享过一个主题《ITDS如何玩转elastic》(这里的ITDS是IT屌丝的意思),里面提到过如何用elasticsearch做数字货币的交易数据分析,回测数据分析等。其中一个问题就是,我们如何把分析结果进行共享。如果我们有一个私人的公网资源最好,没有的话,我们可以用shodan等搜索引擎,搜索免费的资源,然后挂载数据和dashboard template进行共享。

这里,分享以下shodan的API,方便我们随时检测失效的es资源,然后重新获取。

注意,本文章是针对python的

注册shodan并获取API 在shodan的页面上注册一下。(免费用户只能看100个搜索结果,并且不能用条件搜索,坑吧。。。)注册完之后,又上角又一个Show API Key,点击即可看到你的key

这里,假设我们的key是SkVS0RAbiTQpzzEsahqnq2Hv6SwjUfs3(别人的,网上找的,无效 ?) 安装shodan pip3 install shodan

安装完成之后,在你的系统上会又一个shodan CLI

$ shodanUsage: shodan [OPTIONS] COMMAND [ARGS]...Options: -h, --help Show this message and exit.Commands: alert Manage the network alerts for your account convert Convert the given input data file into a... count Returns the number of results for a search data Bulk data access to Shodan domain View all available information for a domain download Download search results and save them in a... honeyscore Check whether the IP is a honeypot or not. host View all available information for an IP... info Shows general information about your account init Initialize the Shodan command-line myip Print your external IP address org Manage your organization's access to Shodan parse Extract information out of compressed JSON... radar Real-Time Map of some results as Shodan finds... scan Scan an IP/ netblock using Shodan. search Search the Shodan database stats Provide summary information about a search... stream Stream data in real-time.

当然,只是以它作为参考,最终我们是要在python脚本里面循环的检查es等资源的可用性,并寻找新的资源。
先试一下:

$ shodan init SkVS0RAbiTQpzzEsahqnq2Hv6SwjUfs3$ shodan count elasticsearch4036

再搜索一下:

$ shodan search --fields ip_str,port,org,hostnames elasticsearch54.36.102.199 8090 OVH SAS 45.199.54.112 80 DXTL Tseung Kwan O Service 159.89.28.238 8880 Digital Ocean porn2gether.com 154.88.111.89 80 Multacom Corporation 154.88.111.83 80 Multacom Corporation 13.53.217.15 8181 Amazon.com ec2-13-53-217-15.eu-north-1.compute.amazonaws.com 62.60.215.71 80 Iranian Research Organization for Science & Techno mx70.myflightmode.com 154.218.48.52 80 CloudInnovation infrastructure 154.197.186.30 80 CloudInnovation infrastructure 154.218.48.38 80 CloudInnovation infrastructure 35.231.19.58 9200 Google Cloud 58.19.231.35.bc.googleusercontent.com 62.60.214.79 80 Iranian Research Organization for Science & Techno 193.58.133.117 80 QuickPacket LLC 54.161.255.217 80 Amazon ec2-54-161-255-217.compute-1.amazonaws.com 45.199.54.106 80 DXTL Tseung Kwan O Service 115.29.9.88 80 Hangzhou Alibaba Advertising Co.,Ltd. 154.88.111.75 80 Multacom Corporation 174.138.57.191 8080 Digital Ocean 35.157.60.25 80 A100 ROW GmbH ec2-35-157-60-25.eu-central-1.compute.amazonaws.com 154.214.154.169 80 CloudInnovation infrastructure 52.178.185.148 9200 Microsoft Azure 154.93.68.123 80 Multacom Corporation 5.196.225.154 9200 OVH SAS 154.ip-5-196-225.eu 154.208.94.212 80 CloudInnovation infrastructure 62.60.214.72 80 Iranian Research Organization for Science & Techno 154.218.44.52 80 CloudInnovation infrastructure 154.93.70.100 80 Multacom Corporation 54.204.112.182 80 Amazon.com ec2-54-204-112-182.compute-1.amazonaws.com 13.81.108.180 80 Microsoft Azure 154.197.184.153 80 CloudInnovation infrastructure 156.235.150.206 80 DXTL Tseung Kwan O Service 45.199.54.70 80 DXTL Tseung Kwan O Service 62.60.208.11 80 Iranian Research Organization for Science & Techno 154.93.69.122 80 Multacom Corporation 101.200.169.192 9200 Hangzhou Alibaba Advertising Co.,Ltd. 193.58.133.103 80 QuickPacket LLC

但因为只有付费的API才能做条件搜索,再此放弃
但还好,我们还有censys

注册censys并获取API

安装censys pip3 install censys 用censys查询可用elasticsearch资源 import censys.certificatesimport censys.ipv4from elasticsearch import ElasticsearchUID = "YOUR ID"SECRET = "YOUR SECRECT"c = censys.ipv4.CensysIPv4(UID, SECRET)i = 0available_es = []for result in c.search("9200.elasticsearch.banner.system_info.version.number: 6.8.0 AND location.country: China", max_records=10): print(result['ip']) available_es.append(result['ip'])for es_ip in available_es: es = Elasticsearch(hosts=[es_ip+':9200']) print(es.cluster.health())

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。