Skip to content

Commit 1f323ce

Browse files
authored
Add subdomains (#11)
* Remove unused import * Add subdomain endpoint * Improve README
1 parent 287f4ee commit 1f323ce

5 files changed

Lines changed: 42 additions & 1 deletion

File tree

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ Docstrings are used to document the library.
1919
Types are also used to inform the user on what type of objects the functions are
2020
expecting.
2121

22+
Each API response is encoded in either a `SuccessResponse` object or a
23+
`ErrorResponse`.
24+
The methods `is_success()` or `is_error()` exist on each API response.
25+
You can get the actual response by using the method `json()` on the response object.
26+
2227
The output are events described in
2328
[l9format](https://github.com/LeakIX/l9format-python).
2429
When you have an object of type `l9Event` (or the longer
@@ -29,6 +34,16 @@ model class for the available fields.
2934
For instance, to access the IP of an object `event` of type `L9Event`, you can
3035
use `event.ip`.
3136

37+
Each object can be transformed back into a Python dictionary/JSON using the method `to_dict()`.
38+
For instance, for the response of the subdomains endpoint, you can get back individual JSON by using:
39+
40+
```python
41+
def example_get_subdomains():
42+
response = CLIENT.get_subdomains("leakix.net")
43+
for subdomain in response.json():
44+
print(subdomain.to_dict())
45+
```
46+
3247
## Support
3348

3449
Feel free to open an issue if you have any question.

example/example_client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ def example_bulk_service():
120120
print(response.json())
121121

122122

123+
def example_get_subdomains():
124+
domain = "leakix.net"
125+
response = CLIENT.get_subdomains(domain)
126+
print(response.json())
127+
128+
123129
if __name__ == "__main__":
124130
example_get_host_filter_plugin()
125131
example_get_service_filter_plugin()
@@ -132,3 +138,4 @@ def example_bulk_service():
132138
example_bulk_export()
133139
example_bulk_service()
134140
example_bulk_export_last_event()
141+
example_get_subdomain()

leakix/client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from leakix.plugin import *
1010
from leakix.plugin import APIResult
1111
from leakix.field import *
12+
from leakix.domain import L9Subdomain
1213

1314

1415
__VERSION__ = "0.1.9"
@@ -153,6 +154,18 @@ def get_plugins(self):
153154
r.response_json = [APIResult.from_dict(d) for d in r.json()]
154155
return r
155156

157+
def get_subdomains(self, domain: str):
158+
"""
159+
Returns the list of subdomains for a given domain.
160+
The output is a list of `L9Subdomain` objects. The fields are `subdomain`, `distinct_ips` and `last_seen`.
161+
To get back a JSON/Python dictionary, use the method `to_dict` on the individual element of the response object.
162+
"""
163+
url = "%s/api/subdomains/%s" % (self.base_url, domain)
164+
r = self.__get(url, params=None)
165+
if r.is_success():
166+
r.response_json = [L9Subdomain.from_dict(d) for d in r.json()]
167+
return r
168+
156169
def bulk_export(self, queries: Optional[List[Query]] = None):
157170
url = "%s/bulk/search" % (self.base_url)
158171
if queries is None or len(queries) == 0:

leakix/domain.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from serde import Model, fields
2+
3+
4+
class L9Subdomain(Model):
5+
subdomain: fields.Str()
6+
distinct_ips: fields.Int()
7+
last_seen: fields.DateTime()

leakix/field.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from leakix.plugin import Plugin
2-
from abc import ABCMeta, abstractmethod
32
from datetime import datetime
43
from typing import Optional
54
from enum import Enum

0 commit comments

Comments
 (0)