Crate bogon

source ·
Expand description

Functions for checking whether an IP address is bogus.

Here “bogus” or “bogon” means an IP address that is not valid for use on the public internet. This includes private IP addresses, loopback addresses, and other reserved addresses. The primary goal of this crate is to provide efficient filters for use in geo-ip tools.

§Example

use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use bogon::is_bogon_str;

assert_eq!(is_bogon_str("127.0.0.1"), Ok(true));
assert_eq!(is_bogon_str("8.8.8.8"), Ok(false));
assert_eq!(is_bogon_str("::1"), Ok(true));
assert!(is_bogon_str("foo").is_err());

assert_eq!(bogon::is_bogon(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1))), true);
assert_eq!(bogon::is_bogon(IpAddr::V4(Ipv4Addr::new(8, 8, 8, 8))), false);
assert_eq!(bogon::is_bogon(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1))), true);

assert_eq!(bogon::is_bogon_v4(Ipv4Addr::new(127, 0, 0, 1)), true);
assert_eq!(bogon::is_bogon_v4(Ipv4Addr::new(8, 8, 8, 8)), false);

assert_eq!(bogon::is_bogon_v6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), true);

Traits§

  • An extension trait for checking if an IP address is in a bogon network.

Functions§

  • Returns a boolean indicating whether an IP address is bogus.
  • Returns a boolean indicating whether an IP address is bogus.
  • Returns a boolean indicating whether an IPv4 address is bogus.
  • Returns a boolean indicating whether an IPv6 address is bogus.