Skip to main content

whois_rust/
lib.rs

1/*!
2# WHOIS Rust
3
4This is a WHOIS client library for Rust, inspired by https://github.com/hjr265/node-whois
5
6## Usage
7
8You can make a **servers.json** file or copy one from https://github.com/hjr265/node-whois
9
10This is a simple example of **servers.json**.
11
12```json
13{
14    "org": "whois.pir.org",
15    "": "whois.ripe.net",
16    "_": {
17        "ip": {
18            "host": "whois.arin.net",
19            "query": "n + $addr\r\n"
20        }
21    }
22}
23```
24
25Then, use the `from_path` (or `from_string` if your JSON data is in-memory) associated function to create a `WhoIs` instance.
26
27```rust,ignore
28use whois_rust::WhoIs;
29
30let whois = WhoIs::from_path("/path/to/servers.json").unwrap();
31```
32
33Use the `lookup` method and input a `WhoIsLookupOptions` instance to lookup a domain or an IP.
34
35```rust,ignore
36use whois_rust::{WhoIs, WhoIsLookupOptions};
37
38let whois = WhoIs::from_path("/path/to/servers.json").unwrap();
39
40let result: String = whois.lookup(WhoIsLookupOptions::from_string("magiclen.org").unwrap()).unwrap();
41```
42
43The `lookup` method decodes the WHOIS response into a `String`. When the response is not valid UTF-8, it is decoded using the `charset` feature (enabled by default). If you need the exact bytes instead, use the `lookup_raw` method, which returns a `Vec<u8>`.
44
45## Asynchronous APIs
46
47You may want to use async APIs with your async runtime. This crate supports `tokio`, currently.
48
49```toml
50[dependencies.whois-rust]
51version = "*"
52features = ["tokio"]
53```
54
55After enabling the async feature, the `from_path_async` function and the `lookup_async` function are available.
56
57## Testing
58
59```bash
60# git clone --recurse-submodules git://github.com/magiclen/whois-rust.git
61
62git clone git://github.com/magiclen/whois-rust.git
63
64cd whois-rust
65
66git submodule init
67git submodule update --recursive
68
69cargo test
70```
71*/
72
73#[cfg(feature = "tokio")]
74pub extern crate tokio;
75
76mod target;
77mod who_is;
78mod who_is_error;
79mod who_is_host;
80mod who_is_lookup_options;
81mod who_is_server_value;
82
83pub use target::*;
84pub use who_is::*;
85pub use who_is_error::*;
86pub use who_is_host::*;
87pub use who_is_lookup_options::*;
88pub use who_is_server_value::*;