Пример #1
0
        /// <summary>
        /// Search Shodan using the same query syntax as the website and use facets to get summary information for different properties.
        /// This method may use API query credits depending on usage. If any of the following criteria are met, your account will be deducated 1 query credit:
        /// 1. The search query contains a filter.
        /// 2. Accessing results past the 1st page using the "page". For every 100 results past the 1st page 1 query credit is deducted.
        /// </summary>
        /// <param name="query">lambda to generate a query. Shodan search query. The provided string is used to search the database of banners in Shodan, with the additional option to provide filters inside the search query using a "filter:value" format.</param>
        /// <param name="facet">static class to define facets.</param>
        /// <param name="page">The page number to page through results 100 at a time (default: 1) </param>
        /// <param name="minify">True or False; whether or not to truncate some of the larger fields (default: True) </param>
        /// <returns></returns>
        public Task <SearchHostResults> SearchHosts(Action <QueryGenerator> query, Action <FacetGenerator> facet = null, int page = 1, bool minify = true)
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }
            var queryGenerator = new QueryGenerator();

            query.Invoke(queryGenerator);
            var queryResult = queryGenerator.Generate();
            var url         = new UriBuilder($"{BasePath}/shodan/host/search")
            {
                Query = $"key={apikey}&query={queryResult}&minify={minify.ToString()}"
            };

            if (facet != null)
            {
                var facetGenerator = new FacetGenerator();
                facet.Invoke(facetGenerator);
                url.Query = $"{url.Query}&facets={facetGenerator.GenerateFacets()}";
            }
            if (page > 1)
            {
                url.Query = $"{url.Query}&page={page}";
            }
            return(RequestHandler.MakeRequestAsync <SearchHostResults>(url.Uri));
        }
Пример #2
0
        /// <summary>
        /// This method behaves identical to <see cref="SearchHosts(SearchQuery, FacetQuery, int, bool)"/>" with the only difference that this method does not return any host results, it only returns the total number of results that matched the query and any facet information that was requested. As a result this method does not consume query credits.
        /// </summary>
        /// <param name="query"></param>
        /// <param name="facet"></param>
        /// <returns></returns>
        public Task <SearchHostResults> SearchHostsCount(Action <QueryGenerator> query, Action <FacetGenerator> facet = null)
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }
            var queryGenObj = new QueryGenerator();

            query.Invoke(queryGenObj);

            var url = new UriBuilder($"{BasePath}/shodan/host/count")
            {
                Query = $"key={apikey}&query={queryGenObj.Generate()}"
            };

            if (facet != null)
            {
                var facetGenObj = new FacetGenerator();
                facet.Invoke(facetGenObj);

                url.Query = $"{url.Query}&facets={facetGenObj.GenerateFacets()}";
            }

            return(RequestHandler.MakeRequestAsync <SearchHostResults>(url.Uri));
        }