watch_hostnames/
watch_hostnames.rs

1use certstreamrs::CertstreamClient;
2use futures_util::{pin_mut, StreamExt};
3
4#[tokio::main]
5async fn main() {
6    // Create the client and open the connection/stream.
7    let client = CertstreamClient::default();
8    let stream = client.watch_certs();
9    pin_mut!(stream);
10
11    // Read from the stream and print the certificate message.
12    loop {
13        let msg = match stream.next().await {
14            Some(msg) => msg.unwrap(),
15            None => continue,
16        };
17
18        // Join the hostnames into a single string.
19        let mut hostnames = String::new();
20        for hostname in msg.data.leaf_cert.all_domains {
21            hostnames.push_str(&hostname);
22            hostnames.push('|');
23        }
24
25        println!(
26            "Source: {} | Hostname(s): {}",
27            msg.data.source.name, hostnames
28        );
29    }
30}