Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

Client for SecurityTrails API

Implementations§

Source§

impl Client

Source

pub fn new(api_key: &str) -> Result<Self, String>

Construct new Client instance with API key

Examples found in repository?
examples/details.rs (line 6)
3fn main() {
4    let api_key: &str = "your_api_key";
5    let domain = "google.com";
6    let client = Client::new(api_key).unwrap();
7    let ping = match client.ping() {
8        Ok(ping) => ping,
9        Err(e) => {
10            println!("{}", e);
11            return;
12        },
13    };
14    println!("ping: {}", ping.success);
15    let details = match client.get_details(domain) {
16        Ok(details) => details,
17        Err(e) => {
18            println!("{}", e);
19            return;
20        },
21    };
22    println!("host_name: {}", details.hostname);
23    println!("endpoint: {}", details.endpoint);
24    println!("current_dns: {:?}", details.current_dns);
25    println!("alexa_rank: {}", details.alexa_rank);
26    let usage = match client.get_usage() {
27        Ok(usage) => usage,
28        Err(e) => {
29            println!("{}", e);
30            return;
31        },
32    };
33    println!("current: {}", usage.current_monthly_usage);
34    println!("allowed: {}", usage.allowed_monthly_usage);
35}
More examples
Hide additional examples
examples/subdomains.rs (line 7)
4fn main() {
5    let api_key: &str = "your_api_key";
6    let domain = "google.com";
7    let client = Client::new(api_key).unwrap();
8    let ping = match client.ping() {
9        Ok(ping) => ping,
10        Err(e) => {
11            println!("{}", e);
12            return;
13        },
14    };
15    println!("ping: {}", ping.success);
16    let subdomains = match client.get_subdomains(domain) {
17        Ok(subdomains) => subdomains,
18        Err(e) => {
19            println!("{}", e);
20            return;
21        },
22    };
23    println!("endpoint: {}", subdomains.endpoint);
24    //println!("subdomains: {:?}", subdomains.subdomains);
25    let joined = subdomains.subdomains.join("\n");
26    let save_path = format!("{}_subdomains.txt", domain);
27    fs::write(save_path.clone(), joined).expect("Unable to write file");
28    println!("subdomains: Saved to {}", save_path);
29    let usage = match client.get_usage() {
30        Ok(usage) => usage,
31        Err(e) => {
32            println!("{}", e);
33            return;
34        },
35    };
36    println!("current: {}", usage.current_monthly_usage);
37    println!("allowed: {}", usage.allowed_monthly_usage);
38}
Source

pub fn set_api_key(&mut self, api_key: String)

Set API key

Source

pub fn set_base_url(&mut self, base_url: String)

Set base URL for API endpoints

Default: https://api.securitytrails.com/v1/

Source

pub fn get_api_key(&self) -> String

Get API key

Source

pub fn get_base_url(&self) -> String

Get base URL for API endpoints

Source

pub fn ping(&self) -> Result<Ping, String>

Test your authentication and access to the SecurityTrails API

Examples found in repository?
examples/details.rs (line 7)
3fn main() {
4    let api_key: &str = "your_api_key";
5    let domain = "google.com";
6    let client = Client::new(api_key).unwrap();
7    let ping = match client.ping() {
8        Ok(ping) => ping,
9        Err(e) => {
10            println!("{}", e);
11            return;
12        },
13    };
14    println!("ping: {}", ping.success);
15    let details = match client.get_details(domain) {
16        Ok(details) => details,
17        Err(e) => {
18            println!("{}", e);
19            return;
20        },
21    };
22    println!("host_name: {}", details.hostname);
23    println!("endpoint: {}", details.endpoint);
24    println!("current_dns: {:?}", details.current_dns);
25    println!("alexa_rank: {}", details.alexa_rank);
26    let usage = match client.get_usage() {
27        Ok(usage) => usage,
28        Err(e) => {
29            println!("{}", e);
30            return;
31        },
32    };
33    println!("current: {}", usage.current_monthly_usage);
34    println!("allowed: {}", usage.allowed_monthly_usage);
35}
More examples
Hide additional examples
examples/subdomains.rs (line 8)
4fn main() {
5    let api_key: &str = "your_api_key";
6    let domain = "google.com";
7    let client = Client::new(api_key).unwrap();
8    let ping = match client.ping() {
9        Ok(ping) => ping,
10        Err(e) => {
11            println!("{}", e);
12            return;
13        },
14    };
15    println!("ping: {}", ping.success);
16    let subdomains = match client.get_subdomains(domain) {
17        Ok(subdomains) => subdomains,
18        Err(e) => {
19            println!("{}", e);
20            return;
21        },
22    };
23    println!("endpoint: {}", subdomains.endpoint);
24    //println!("subdomains: {:?}", subdomains.subdomains);
25    let joined = subdomains.subdomains.join("\n");
26    let save_path = format!("{}_subdomains.txt", domain);
27    fs::write(save_path.clone(), joined).expect("Unable to write file");
28    println!("subdomains: Saved to {}", save_path);
29    let usage = match client.get_usage() {
30        Ok(usage) => usage,
31        Err(e) => {
32            println!("{}", e);
33            return;
34        },
35    };
36    println!("current: {}", usage.current_monthly_usage);
37    println!("allowed: {}", usage.allowed_monthly_usage);
38}
Source

pub fn get_usage(&self) -> Result<Usage, String>

Returns Usage statistics of the API for the current month

Examples found in repository?
examples/details.rs (line 26)
3fn main() {
4    let api_key: &str = "your_api_key";
5    let domain = "google.com";
6    let client = Client::new(api_key).unwrap();
7    let ping = match client.ping() {
8        Ok(ping) => ping,
9        Err(e) => {
10            println!("{}", e);
11            return;
12        },
13    };
14    println!("ping: {}", ping.success);
15    let details = match client.get_details(domain) {
16        Ok(details) => details,
17        Err(e) => {
18            println!("{}", e);
19            return;
20        },
21    };
22    println!("host_name: {}", details.hostname);
23    println!("endpoint: {}", details.endpoint);
24    println!("current_dns: {:?}", details.current_dns);
25    println!("alexa_rank: {}", details.alexa_rank);
26    let usage = match client.get_usage() {
27        Ok(usage) => usage,
28        Err(e) => {
29            println!("{}", e);
30            return;
31        },
32    };
33    println!("current: {}", usage.current_monthly_usage);
34    println!("allowed: {}", usage.allowed_monthly_usage);
35}
More examples
Hide additional examples
examples/subdomains.rs (line 29)
4fn main() {
5    let api_key: &str = "your_api_key";
6    let domain = "google.com";
7    let client = Client::new(api_key).unwrap();
8    let ping = match client.ping() {
9        Ok(ping) => ping,
10        Err(e) => {
11            println!("{}", e);
12            return;
13        },
14    };
15    println!("ping: {}", ping.success);
16    let subdomains = match client.get_subdomains(domain) {
17        Ok(subdomains) => subdomains,
18        Err(e) => {
19            println!("{}", e);
20            return;
21        },
22    };
23    println!("endpoint: {}", subdomains.endpoint);
24    //println!("subdomains: {:?}", subdomains.subdomains);
25    let joined = subdomains.subdomains.join("\n");
26    let save_path = format!("{}_subdomains.txt", domain);
27    fs::write(save_path.clone(), joined).expect("Unable to write file");
28    println!("subdomains: Saved to {}", save_path);
29    let usage = match client.get_usage() {
30        Ok(usage) => usage,
31        Err(e) => {
32            println!("{}", e);
33            return;
34        },
35    };
36    println!("current: {}", usage.current_monthly_usage);
37    println!("allowed: {}", usage.allowed_monthly_usage);
38}
Source

pub fn get_details(&self, domain: &str) -> Result<Details, String>

Returns the current data about the given hostname(domain)

Examples found in repository?
examples/details.rs (line 15)
3fn main() {
4    let api_key: &str = "your_api_key";
5    let domain = "google.com";
6    let client = Client::new(api_key).unwrap();
7    let ping = match client.ping() {
8        Ok(ping) => ping,
9        Err(e) => {
10            println!("{}", e);
11            return;
12        },
13    };
14    println!("ping: {}", ping.success);
15    let details = match client.get_details(domain) {
16        Ok(details) => details,
17        Err(e) => {
18            println!("{}", e);
19            return;
20        },
21    };
22    println!("host_name: {}", details.hostname);
23    println!("endpoint: {}", details.endpoint);
24    println!("current_dns: {:?}", details.current_dns);
25    println!("alexa_rank: {}", details.alexa_rank);
26    let usage = match client.get_usage() {
27        Ok(usage) => usage,
28        Err(e) => {
29            println!("{}", e);
30            return;
31        },
32    };
33    println!("current: {}", usage.current_monthly_usage);
34    println!("allowed: {}", usage.allowed_monthly_usage);
35}
Source

pub fn get_subdomains(&self, domain: &str) -> Result<Subdomains, String>

Returns child and sibling subdomains for a given hostname(domain)

Examples found in repository?
examples/subdomains.rs (line 16)
4fn main() {
5    let api_key: &str = "your_api_key";
6    let domain = "google.com";
7    let client = Client::new(api_key).unwrap();
8    let ping = match client.ping() {
9        Ok(ping) => ping,
10        Err(e) => {
11            println!("{}", e);
12            return;
13        },
14    };
15    println!("ping: {}", ping.success);
16    let subdomains = match client.get_subdomains(domain) {
17        Ok(subdomains) => subdomains,
18        Err(e) => {
19            println!("{}", e);
20            return;
21        },
22    };
23    println!("endpoint: {}", subdomains.endpoint);
24    //println!("subdomains: {:?}", subdomains.subdomains);
25    let joined = subdomains.subdomains.join("\n");
26    let save_path = format!("{}_subdomains.txt", domain);
27    fs::write(save_path.clone(), joined).expect("Unable to write file");
28    println!("subdomains: Saved to {}", save_path);
29    let usage = match client.get_usage() {
30        Ok(usage) => usage,
31        Err(e) => {
32            println!("{}", e);
33            return;
34        },
35    };
36    println!("current: {}", usage.current_monthly_usage);
37    println!("allowed: {}", usage.allowed_monthly_usage);
38}
Source

pub fn get_tags(&self, domain: &str) -> Result<Tags, String>

Returns tags for a given hostname(domain)

Source

pub fn get_whois(&self, domain: &str) -> Result<Whois, String>

Returns the current WHOIS data about a given hostname(domain)

Auto Trait Implementations§

§

impl Freeze for Client

§

impl RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnwindSafe for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,