#domain-name #parser

dns_name

DNS name parsing with public suffix lookup

2 stable releases

1.0.1 Jan 10, 2024
1.0.0 Feb 24, 2023

#43 in #domain-name

Download history 45/week @ 2024-07-19 83/week @ 2024-07-26 19/week @ 2024-08-02 66/week @ 2024-08-09 36/week @ 2024-08-16 76/week @ 2024-08-23 26/week @ 2024-08-30 10/week @ 2024-09-06 59/week @ 2024-09-13 61/week @ 2024-09-20 20/week @ 2024-09-27 68/week @ 2024-10-04 40/week @ 2024-10-11 7/week @ 2024-10-18 44/week @ 2024-11-01

108 downloads per month

MIT license

45KB
437 lines

dns_name

Robust domain name parsing using the Public Suffix List

This library allows you to easily and accurately parse any given domain name.

let list = List::from_path("suffix-list.txt").unwrap();

let domain = list.parse_dns_name("www.example.com")?;
assert_eq!(domain.name(), "www.example.com");
assert_eq!(domain.rname(), "moc.elpmaxe.www");
assert_eq!(domain.root(), Some("example.com"));
assert_eq!(domain.suffix(), Some("com"));
assert_eq!(domain.registrable(), Some("example"));

// 2-level TLD
let domain = list.parse_dns_name("wWw.BlUeCaTnEtWoRkS.Uk.CoM.")?;
assert_eq!(domain.name(), "www.bluecatnetworks.uk.com.");
assert_eq!(domain.rname(), ".moc.ku.skrowtentaceulb.www");
assert_eq!(domain.root(), Some("bluecatnetworks.uk.com."));
assert_eq!(domain.suffix(), Some("uk.com."));
assert_eq!(domain.registrable(), Some("bluecatnetworks"));

// the root name
let domain = list.parse_dns_name(".")?;
assert_eq!(domain.name(), ".");
assert_eq!(domain.rname(), ".");
assert_eq!(domain.root(), None);
assert_eq!(domain.suffix(), None);
assert_eq!(domain.registrable(), None);

Dependencies

~8MB
~153K SLoC