33
44The Censys Search API provides functionality for interacting with Censys resources such as Hosts.
55
6- There are three API options that this library provides access to:
6+ There are three main API endpoints that this library provides access to:
77
88- :attr: `search <censys.search.v2.api.CensysSearchAPIv2.search> ` - Allows searches against the Hosts index using the same search syntax as the `web app <https://search.censys.io/search/language?resource=hosts >`__.
99- :attr: `view <censys.search.v2.api.CensysSearchAPIv2.view> ` - Returns the structured data we have about a specific Host, given the resource's natural ID.
@@ -23,173 +23,83 @@ Python class objects must be initialized for each resource index (Hosts).
2323``search ``
2424----------
2525
26- Below we show an example using the :attr: `CensysHosts <censys.search.v2.CensysHosts> ` index.
27-
28- .. code :: python
29-
30- # !/usr/bin/env python3
31- from censys.search import CensysHosts
32-
33- h = CensysHosts()
34-
35- # Single page of search results
36- query = h.search(" service.service_name: HTTP" , per_page = 5 )
37- print (query())
26+ **Please note this method is only available only for the CensysHosts index. **
3827
39- # Multiple pages of search results
40- # You can optionally pass in a number of results to be returned
41- # each page and the number of pages you want returned.
42- for page in h.search(" service.service_name: HTTP" , per_page = 5 , pages = 2 ):
43- print (page)
44-
45- # You can also get all pages of results by using -1 for pages
46- for page in h.search(" service.service_name: HTTP" , pages = - 1 ):
47- print (page)
28+ Below we show an example using the :attr: `CensysHosts <censys.search.v2.CensysHosts> ` index.
4829
49- # View each result returned
50- # For `hosts` this looks like a mapping of IPs to view results
51- query = h.search(" service.service_name: HTTP" , per_page = 5 , pages = 2 )
52- print (query.view_all())
30+ .. include :: ../examples/search/search_hosts.py
31+ :literal:
5332
5433``view ``
5534--------
5635
57- Below we show an example using the :attr: ` CensysHosts <censys.search.v2.CensysHosts> ` index.
36+ ** Please note this method is only available only for the CensysHosts index.**
5837
59- .. code :: python
38+ Below we show an example using the :attr: ` CensysHosts <censys.search.v2.CensysHosts> ` index.
6039
61- from censys.search import CensysHosts
40+ .. include :: ../examples/search/view_host.py
41+ :literal:
6242
63- h = CensysHosts()
64-
65- # Fetch a specific host and its services
66- host = h.view(" 8.8.8.8" )
67- print (host)
43+ ``bulk_view ``
44+ -------------
6845
69- # You can optionally pass in a RFC3339 timestamp to
70- # fetch a host at the given point in time.
71- # Please note historical API access is required.
72- host = h.view(" 8.8.8.8" , at_time = " 2021-03-01T17:49:05Z" )
73- print (host)
46+ **Please note this method is only available only for the CensysHosts index. **
7447
75- # You can also pass in a date or datetime object.
76- from datetime import date
48+ Below we show an example using the :attr: `CensysHosts <censys.search.v2.CensysHosts> ` index.
7749
78- host = h.view( " 8.8.8.8 " , at_time = date( 2021 , 3 , 1 ))
79- print (host)
50+ .. include :: ../examples/search/bulk_view_hosts.py
51+ :literal:
8052
8153``aggregate ``
8254-------------
8355
84- Below we show an example using the :attr: `CensysHosts <censys.search.v2.CensysHosts> ` index.
85-
86- .. code :: python
87-
88- from censys.search import CensysHosts
56+ **Please note this method is only available only for the CensysHosts index. **
8957
90- h = CensysHosts()
58+ Below we show an example using the :attr: ` CensysHosts <censys.search.v2.CensysHosts> ` index.
9159
92- # The aggregate method constructs a report using a query, an aggregation field, and the
93- # number of buckets to bin.
94- report = h.aggregate(
95- " service.service_name: HTTP" ,
96- " services.port" ,
97- num_buckets = 5 ,
98- )
99- print (report)
60+ .. include :: ../examples/search/aggregate_hosts.py
61+ :literal:
10062
10163``metadata ``
10264-------------
10365
104- **Please note this method is only available only for the CensysHosts index **
66+ **Please note this method is only available only for the CensysHosts index. **
10567
10668Below we show an example using the :attr: `CensysHosts <censys.search.v2.CensysHosts> ` index.
10769
108- .. code :: python
109-
110- from censys.search import CensysHosts
111-
112- h = CensysHosts()
113-
114- # Fetch metadata about hosts.
115- meta = h.metadata()
116- print (meta.get(" services" ))
70+ .. include :: ../examples/search/metadata_hosts.py
71+ :literal:
11772
11873``view_host_names ``
11974-------------------
12075
121- **Please note this method is only available only for the CensysHosts index **
76+ **Please note this method is only available only for the CensysHosts index. **
12277
12378Below we show an example using the :attr: `CensysHosts <censys.search.v2.CensysHosts> ` index.
12479
125- .. code :: python
126-
127- from censys.search import CensysHosts
128-
129- h = CensysHosts()
130-
131- # Fetch a list of host names for the specified IP address.
132- names = h.view_host_names(" 1.1.1.1" )
133- print (names)
80+ .. include :: ../examples/search/view_host_names.py
81+ :literal:
13482
13583``view_host_events ``
13684--------------------
13785
138- **Please note this method is only available only for the CensysHosts index **
86+ **Please note this method is only available only for the CensysHosts index. **
13987
14088Below we show an example using the :attr: `CensysHosts <censys.search.v2.CensysHosts> ` index.
14189
142- .. code :: python
143-
144- from censys.search import CensysHosts
145-
146- h = CensysHosts()
147-
148- # Fetch a list of events for the specified IP address.
149- events = h.view_host_events(" 1.1.1.1" )
150- print (events)
151-
152- # You can also pass in a date or datetime objects.
153- from datetime import date
154-
155- events = h.view_host_events(
156- " 1.1.1.1" , start_time = date(2021 , 7 , 1 ), end_time = date(2021 , 7 , 31 )
157- )
158- print (events)
90+ .. include :: ../examples/search/view_host_events.py
91+ :literal:
15992
16093``view_host_diff ``
16194------------------
16295
163- **Please note this method is only available only for the CensysHosts index **
96+ **Please note this method is only available only for the CensysHosts index. **
16497
16598Below we show an example using the :attr: `CensysHosts <censys.search.v2.CensysHosts> ` index.
16699
167- .. code :: python
168-
169- from censys.search import CensysHosts
170-
171- h = CensysHosts()
172-
173- # Compare a single host between two timestamps
174- diff = c.view_host_diff(" 1.1.1.1" , at_time = date(2022 , 1 , 1 ), at_time_b = date(2022 , 1 , 2 ))
175- print (diff)
100+ .. include :: ../examples/search/view_host_diff.py
101+ :literal:
176102
177- # Compare a single host between its current timestamp and a timestamp
178- diff = c.view_host_diff(" 1.1.1.2" , at_time = date(2022 , 1 , 2 ))
179- print (diff)
180-
181- # Compare two hosts
182- diff = c.view_host_diff(" 1.1.1.1" , ip_b = " 1.1.1.2" )
183- print (diff)
184-
185- # Compare two hosts between two timestamps
186- diff = c.view_host_diff(
187- " 1.1.1.1" ,
188- ip_b = " 1.1.1.2" ,
189- at_time = date(2022 , 1 , 1 ),
190- at_time_b = date(2022 , 1 , 2 ),
191- )
192- print (diff)
193103
194104``get_hosts_by_cert ``
195105---------------------
@@ -427,7 +337,7 @@ Below we show an example using the :attr:`CensysCerts <censys.search.v2.CensysCe
427337 ``list_hosts_with_tag ``
428338^^^^^^^^^^^^^^^^^^^^^^^
429339
430- **Please note this method is only available only for the CensysHosts index **
340+ **Please note this method is only available only for the CensysHosts index. **
431341
432342Below we show an example using the :attr: `CensysHosts <censys.search.v2.CensysHosts> ` index.
433343
0 commit comments