Shodan.Net
c# client for the shodan api
Public Member Functions | Protected Member Functions | List of all members
Shodan.Net.ShodanClient Class Reference

Main mechanism to talk to the shodan api. This is what you should use to interact with the api More...

Inheritance diagram for Shodan.Net.ShodanClient:

Public Member Functions

 ShodanClient (string apikey)
 
Task< Dictionary< string, string > > DnsLookupAsync (string hostnames)
 Look up the IP address for the provided list of hostnames. More...
 
Task< SearchHostResultsSearchHosts (Action< QueryGenerator > query, Action< FacetGenerator > facet=null, int page=1, bool minify=true)
 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: More...
 
Task< SearchHostResultsSearchHostsCount (Action< QueryGenerator > query, Action< FacetGenerator > facet=null)
 This method behaves identical to 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. More...
 
Task< SearchTokensSearchTokens (Action< QueryGenerator > query)
 
async Task< double > Experimental_GetHoneyPotScoreAsync (string ip)
 Calculates a honeypot probability score ranging from 0 (not a honeypot) to 1.0 (is a honeypot). More...
 
Task< ApiStatusGetApiStatusAsync ()
 Returns information about the API plan belonging to the given API key. More...
 
Task< HostGetHostAsync (string Ip, bool history=false, bool minify=false)
 Returns all services that have been found on the given host IP. More...
 
Task< string > GetMyIpAsync ()
 Get your current IP address as seen from the Internet. More...
 
Task< List< int > > GetPortsAsync ()
 This method returns a list of port numbers that the crawlers are looking for. More...
 
Task< ProfileGetProfileAsync ()
 Returns information about the Shodan account linked to this API key. More...
 
Task< Dictionary< string, string > > GetProtocolsAsync ()
 This method returns an object containing all the protocols that can be used when launching an Internet scan. More...
 
Task< SearchQueriesGetQueriesAsync (int?page=null, SortOptions?sort=null, OrderOption?order=null)
 Use this method to obtain a list of search queries that users have saved in Shodan. More...
 
Task< SearchQueriesSearchQueriesAsync (string query, int?page=null)
 Use this method to search the directory of search queries that users have saved in Shodan. More...
 
Task< ScanStatusGetScanStatusAsync (string id)
 Check the progress of a previously submitted scan request More...
 
Task< Dictionary< string, string > > GetServicesAsync ()
 This method returns an object containing all the services that the Shodan crawlers look at. It can also be used as a quick and practical way to resolve a port number to the name of a service More...
 
Task< TagResultGetTagsAsync (int size=10)
 Use this method to obtain a list of popular tags for the saved search queries in Shodan. More...
 
Task< ScanPortResultRequestInternetPortScanAsync (int port, string protocol)
 Use this method to request Shodan to crawl the Internet for a specific port. This method is restricted to security researchers and companies with a Shodan Data license. To apply for access to this method as a researcher, please email jmath.nosp@m.@sho.nosp@m.dan.i.nosp@m.o with information about your project. Access is restricted to prevent abuse. More...
 
Task< ScanResultRequstScanAsync (string ips)
 Use this method to request Shodan to crawl a network Requirements: This method uses API scan credits: 1 IP consumes 1 scan credit. You must have a paid API plan (either one-time payment or subscription) in order to use this method More...
 
Task< Dictionary< string, List< string > > > ReverseLookupAsync (string ips)
 Look up the hostnames that have been defined for the given list of IP addresses More...
 
void Dispose ()
 

Protected Member Functions

virtual void Dispose (bool disposing)
 

Detailed Description

Main mechanism to talk to the shodan api. This is what you should use to interact with the api

Member Function Documentation

Task<Dictionary<string, string> > Shodan.Net.ShodanClient.DnsLookupAsync ( string  hostnames)
inline

Look up the IP address for the provided list of hostnames.

Parameters
hostnamesComma-separated list of hostnames; example "google.com,bing.com"
Returns
46  {
47  if(string.IsNullOrWhiteSpace(hostnames))
48  {
49  throw new ArgumentNullException(hostnames);
50  }
51  var url = new Uri($"{BasePath}/dns/resolve?hostnames={hostnames}&key={this.apikey}");
52  return RequestHandler.MakeRequestAsync<Dictionary<string, string>>(url);
53  }
async Task<double> Shodan.Net.ShodanClient.Experimental_GetHoneyPotScoreAsync ( string  ip)
inline

Calculates a honeypot probability score ranging from 0 (not a honeypot) to 1.0 (is a honeypot).

Parameters
ip
Returns
140  {
141  if(string.IsNullOrWhiteSpace(ip))
142  {
143  throw new ArgumentNullException(nameof(ip));
144  }
145  var url = new Uri($"{BasePath}/labs/honeyscore/{ip}?key={apikey}");
146  var result = await RequestHandler.MakeRequestAsync<string>(url);
147  double resultParsed;
148  if(!double.TryParse(result, out resultParsed))
149  {
150  throw new ShodanException($"honeypot score returned with {result} failed to parse to double");
151  }
152  return resultParsed;
153  }
Task<ApiStatus> Shodan.Net.ShodanClient.GetApiStatusAsync ( )
inline

Returns information about the API plan belonging to the given API key.

Returns
160  {
161  var url = new Uri($"{BasePath}/api-info?key={apikey}");
162  return RequestHandler.MakeRequestAsync<ApiStatus>(url);
163  }
Returns information about the API plan belonging to the given API key.
Definition: ApiStatus.cs:13
Task<Host> Shodan.Net.ShodanClient.GetHostAsync ( string  Ip,
bool  history = false,
bool  minify = false 
)
inline

Returns all services that have been found on the given host IP.

Parameters
IpHost IP address
historyTrue if all historical banners should be returned (default: False)
minifyTrue to only return the list of ports and the general host information, no banners. (default: False)
Returns
173  {
174  if(string.IsNullOrWhiteSpace(Ip))
175  {
176  throw new ArgumentNullException(nameof(Ip));
177  }
178  var builder = new UriBuilder($"{BasePath}/shodan/host/{Ip}")
179  {
180  Query = $"key={this.apikey}&history={history.ToString()}&minify={minify.ToString()}"
181  };
182 
183  return RequestHandler.MakeRequestAsync<Host>(builder.Uri);
184  }
Represents return data for querying hosts
Definition: Host.cs:13
Task<string> Shodan.Net.ShodanClient.GetMyIpAsync ( )
inline

Get your current IP address as seen from the Internet.

Returns
191  {
192  var url = new Uri($"{BasePath}/tools/myip?key={this.apikey}");
193  return RequestHandler.MakeRequestAsync<string>(url);
194  }
Task<List<int> > Shodan.Net.ShodanClient.GetPortsAsync ( )
inline

This method returns a list of port numbers that the crawlers are looking for.

Returns
201  {
202  var builder = new Uri($"{BasePath}/shodan/ports?key={this.apikey}");
203  return RequestHandler.MakeRequestAsync<List<int>>(builder);
204  }
Task<Profile> Shodan.Net.ShodanClient.GetProfileAsync ( )
inline

Returns information about the Shodan account linked to this API key.

Returns
211  {
212  var url = new Uri($"{BasePath}/account/profile?key={apikey}");
213  return RequestHandler.MakeRequestAsync<Profile>(url);
214  }
Represents data about your profile
Definition: Profile.cs:13
Task<Dictionary<string, string> > Shodan.Net.ShodanClient.GetProtocolsAsync ( )
inline

This method returns an object containing all the protocols that can be used when launching an Internet scan.

Returns
221  {
222  var url = new Uri($"{BasePath}/shodan/protocols?key={this.apikey}");
223  return RequestHandler.MakeRequestAsync<Dictionary<string, string>>(url);
224  }
Task<SearchQueries> Shodan.Net.ShodanClient.GetQueriesAsync ( int?  page = null,
SortOptions sort = null,
OrderOption order = null 
)
inline

Use this method to obtain a list of search queries that users have saved in Shodan.

Parameters
pagePage number to iterate over results; each page contains 10 items
sortSort the list based on a property. Possible values are: votes, timestamp
orderWhether to sort the list in ascending or descending order. Possible values are: asc, desc
Returns
234  {
235  var url = new UriBuilder($"{BasePath}/shodan/query")
236  {
237  Query = $"key={apikey}"
238  };
239  if(sort.HasValue)
240  {
241  var sortName = Enum.GetName(typeof(SortOptions), sort.Value);
242  url.Query = $"{url.Query}&sort={sortName}";
243  }
244  if(order.HasValue)
245  {
246  var orderName = Enum.GetName(typeof(OrderOption), order.Value);
247  url.Query = $"{url.Query}&order={orderName}";
248  }
249  return RequestHandler.MakeRequestAsync<SearchQueries>(url.Uri);
250  }
Result of ShodanClient.GetQueriesAsync(int?, SortOptions?, OrderOption?) and ShodanClient.SearchQueriesAsync(string, int?)
Definition: SearchQueries.cs:35
OrderOption
Represents an order of either ascending or descending
Definition: OrderOption.cs:11
SortOptions
Represents an option to sort
Definition: SortOptions.cs:11
Task<ScanStatus> Shodan.Net.ShodanClient.GetScanStatusAsync ( string  id)
inline

Check the progress of a previously submitted scan request

Parameters
idthe unique scan ID that was returned by RequstScanAsync(string)
Returns
281  {
282  if(string.IsNullOrWhiteSpace(id))
283  {
284  throw new ArgumentNullException(nameof(id));
285  }
286  var url = new Uri($"{BasePath}/shodan/scan/{id}");
287  return RequestHandler.MakeRequestAsync<ScanStatus>(url);
288  }
Result of ShodanClient.GetScanStatusAsync(string)
Definition: ScanStatus.cs:14
Task<Dictionary<string, string> > Shodan.Net.ShodanClient.GetServicesAsync ( )
inline

This method returns an object containing all the services that the Shodan crawlers look at. It can also be used as a quick and practical way to resolve a port number to the name of a service

Returns
295  {
296  var url = new Uri($"{BasePath}/shodan/services?key={this.apikey}");
297  return RequestHandler.MakeRequestAsync<Dictionary<string, string>>(url);
298  }
Task<TagResult> Shodan.Net.ShodanClient.GetTagsAsync ( int  size = 10)
inline

Use this method to obtain a list of popular tags for the saved search queries in Shodan.

Parameters
sizeThe number of tags to return
Returns
306  {
307  var url = new UriBuilder($"{BasePath}/shodan/query/tags")
308  {
309  Query = $"key={apikey}&size={size}"
310  };
311  return RequestHandler.MakeRequestAsync<TagResult>(url.Uri);
312  }
result of ShodanClient.GetTagsAsync(int)
Definition: TagResult.cs:13
Task<ScanPortResult> Shodan.Net.ShodanClient.RequestInternetPortScanAsync ( int  port,
string  protocol 
)
inline

Use this method to request Shodan to crawl the Internet for a specific port. This method is restricted to security researchers and companies with a Shodan Data license. To apply for access to this method as a researcher, please email jmath.nosp@m.@sho.nosp@m.dan.i.nosp@m.o with information about your project. Access is restricted to prevent abuse.

Parameters
portThe port that Shodan should crawl the Internet for.
protocolThe name of the protocol that should be used to interrogate the port. See GetProtocolsAsync for a list of supported protocols.
Returns
322  {
323  var url = new Uri($"{BasePath}/shodan/scan/internet?key={this.apikey}");
324  using(var data = new FormUrlEncodedContent(new List<KeyValuePair<string, string>>() {
325  new KeyValuePair<string, string>("port", port.ToString()),
326  new KeyValuePair<string, string>("protocol", protocol)
327  }))
328  {
329  return RequestHandler.MakeRequestAsync<ScanPortResult>(url, data, RequestType.POST);
330  }
331  }
result of ShodanClient.RequestInternetPortScanAsync(int, string)
Definition: ScanPortResult.cs:13
Task<ScanResult> Shodan.Net.ShodanClient.RequstScanAsync ( string  ips)
inline

Use this method to request Shodan to crawl a network Requirements: This method uses API scan credits: 1 IP consumes 1 scan credit. You must have a paid API plan (either one-time payment or subscription) in order to use this method

Parameters
ips
Returns
340  {
341  if(string.IsNullOrWhiteSpace(ips))
342  {
343  throw new ArgumentNullException(nameof(ips));
344  }
345  if(!ips.Split(',').Any())
346  {
347  throw new ArgumentOutOfRangeException($"{ips} must have one valid record");
348  }
349  var url = new Uri($"{BasePath}/shodan/scan?key={this.apikey}");
350  using(var data = new FormUrlEncodedContent(new KeyValuePair<string, string>[] { new KeyValuePair<string, string>("ips", ips) }))
351  {
352  return RequestHandler.MakeRequestAsync<ScanResult>(url, data, RequestType.POST);
353  }
354  }
result of ShodanClient.RequstScanAsync(string)
Definition: ScanResult.cs:13
Task<Dictionary<string, List<string> > > Shodan.Net.ShodanClient.ReverseLookupAsync ( string  ips)
inline

Look up the hostnames that have been defined for the given list of IP addresses

Parameters
ipsComma-separated list of IP addresses; example "74.125.227.230,204.79.197.200"
Returns
362  {
363  if(string.IsNullOrWhiteSpace(ips))
364  {
365  throw new ArgumentNullException(ips);
366  }
367  var url = new Uri($"{BasePath}/dns/reverse?ips={ips}&key={this.apikey}");
368  return RequestHandler.MakeRequestAsync<Dictionary<string, List<string>>>(url);
369  }
Task<SearchHostResults> Shodan.Net.ShodanClient.SearchHosts ( Action< QueryGenerator query,
Action< FacetGenerator facet = null,
int  page = 1,
bool  minify = true 
)
inline

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.
Parameters
querylambda 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.
facetstatic class to define facets.
pageThe page number to page through results 100 at a time (default: 1)
minifyTrue or False; whether or not to truncate some of the larger fields (default: True)
Returns
67  {
68  if(query == null)
69  {
70  throw new ArgumentNullException(nameof(query));
71  }
72  var queryGenerator = new QueryGenerator();
73  query.Invoke(queryGenerator);
74  var queryResult = queryGenerator.Generate();
75  var url = new UriBuilder($"{BasePath}/shodan/host/search")
76  {
77  Query = $"key={apikey}&query={queryResult}&minify={minify.ToString()}"
78  };
79  if(facet != null)
80  {
81  var facetGenerator = new FacetGenerator();
82  facet.Invoke(facetGenerator);
83  url.Query = $"{url.Query}&facets={facetGenerator.GenerateFacets()}";
84  }
85  if(page > 1)
86  {
87  url.Query = $"{url.Query}&page={page}";
88  }
89  return RequestHandler.MakeRequestAsync<SearchHostResults>(url.Uri);
90  }
result of ShodanClient.SearchHosts(SearchQuery, FacetQuery, int, bool) and ShodanClient.SearchHostsCount(SearchQuery, FacetQuery)
Definition: SearchHostResults.cs:13
Task<SearchHostResults> Shodan.Net.ShodanClient.SearchHostsCount ( Action< QueryGenerator query,
Action< FacetGenerator facet = null 
)
inline

This method behaves identical to 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.

Parameters
query
facet
Returns
99  {
100  if(query == null)
101  {
102  throw new ArgumentNullException(nameof(query));
103  }
104  var queryGenObj = new QueryGenerator();
105  query.Invoke(queryGenObj);
106 
107  var url = new UriBuilder($"{BasePath}/shodan/host/count")
108  {
109  Query = $"key={apikey}&query={queryGenObj.Generate()}"
110  };
111  if(facet != null)
112  {
113  var facetGenObj = new FacetGenerator();
114  facet.Invoke(facetGenObj);
115 
116  url.Query = $"{url.Query}&facets={facetGenObj.GenerateFacets()}";
117  }
118 
119  return RequestHandler.MakeRequestAsync<SearchHostResults>(url.Uri);
120  }
result of ShodanClient.SearchHosts(SearchQuery, FacetQuery, int, bool) and ShodanClient.SearchHostsCount(SearchQuery, FacetQuery)
Definition: SearchHostResults.cs:13
Task<SearchQueries> Shodan.Net.ShodanClient.SearchQueriesAsync ( string  query,
int?  page = null 
)
inline

Use this method to search the directory of search queries that users have saved in Shodan.

Parameters
queryWhat to search for in the directory of saved search queries.
pagePage number to iterate over results; each page contains 10 items
Returns
259  {
260  if(string.IsNullOrWhiteSpace(query))
261  {
262  throw new ArgumentNullException(query);
263  }
264  var url = new UriBuilder($"{BasePath}/shodan/query/search")
265  {
266  Query = $"key={apikey}&query={query}"
267  };
268  if(page != null)
269  {
270  url.Query = $"{url.Query}&page={page}";
271  }
272  return RequestHandler.MakeRequestAsync<SearchQueries>(url.Uri);
273  }
Result of ShodanClient.GetQueriesAsync(int?, SortOptions?, OrderOption?) and ShodanClient.SearchQueriesAsync(string, int?)
Definition: SearchQueries.cs:35

The documentation for this class was generated from the following file: