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.

§Cargo Features

  • download: Download the latest IPv6 address allocations from the IANA website during the build process. Requires a network connection.

§Example

use core::net::{IpAddr, Ipv4Addr, Ipv6Addr};

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

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);

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);

use bogon::BogonExt;

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

Traits§

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

Functions§

is_bogon
Returns a boolean indicating whether an IP address is bogus.
is_bogon_str
Returns a boolean indicating whether an IP address is bogus.
is_bogon_v4
Returns a boolean indicating whether an IPv4 address is bogus.
is_bogon_v6
Returns a boolean indicating whether an IPv6 address is bogus.