IpNetwork
Represents IP network allocation information returned from RDAP queries for IP addresses and CIDR blocks.
Always “ip network” for IP network objects
RDAP conformance levels (e.g., ["rdap_level_0"])
Registry-unique identifier for the network allocationlet net_handle = network.handle.unwrap_or_default();
First IP address in the network rangeif let Some(start) = &network.start_address {
println!("Network starts at: {}", start);
}
Last IP address in the network rangeif let Some(end) = &network.end_address {
println!("Network ends at: {}", end);
}
IP version: “v4” or “v6”match network.ip_version.as_deref() {
Some("v4") => println!("IPv4 network"),
Some("v6") => println!("IPv6 network"),
_ => println!("Unknown version"),
}
Network name or identifier
Type of allocation (e.g., “ALLOCATED”, “ASSIGNED”)
ISO 3166-1 alpha-2 country codeif let Some(country) = &network.country {
println!("Allocated to: {}", country);
}
Handle of the parent network allocation
Network status values (e.g., “active”, “reserved”)
Related entities (registrants, abuse contacts, etc.). See Entity// Find abuse contact
let abuse = network.entities.iter()
.find(|e| e.roles.contains(&"abuse".to_string()))
.and_then(|e| e.vcard.as_ref())
.and_then(|v| v.email());
if let Some(email) = abuse {
println!("Abuse contact: {}", email);
}
WHOIS server hostname for port 43 queries
Lifecycle events (allocation, last changed, etc.). See common fields// Find allocation date
let allocated = network.events.iter()
.find(|e| e.action == "registration" || e.action == "last changed")
.map(|e| &e.date);
Language tag (e.g., “en”, “fr”)
Example Usage
use rdap_client::RdapClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = RdapClient::new();
// Query an IP address
let result = client.query("8.8.8.8").await?;
if let Some(network) = result.ip_network() {
println!("Network: {} - {}",
network.start_address.as_deref().unwrap_or("N/A"),
network.end_address.as_deref().unwrap_or("N/A")
);
println!("Name: {}", network.name.as_deref().unwrap_or("N/A"));
println!("Type: {}", network.network_type.as_deref().unwrap_or("N/A"));
println!("Country: {}", network.country.as_deref().unwrap_or("N/A"));
// Find abuse contact
for entity in &network.entities {
if entity.roles.contains(&"abuse".to_string()) {
if let Some(vcard) = &entity.vcard {
if let Some(email) = vcard.email() {
println!("Abuse: {}", email);
}
}
}
}
// Show allocation date
for event in &network.events {
if event.action == "registration" {
println!("Allocated: {}", event.date);
}
}
}
Ok(())
}
CIDR Query Example
// Query a CIDR block
let result = client.query("192.0.2.0/24").await?;
if let Some(network) = result.ip_network() {
println!("CIDR block information:");
println!(" Range: {} - {}",
network.start_address.as_deref().unwrap_or("N/A"),
network.end_address.as_deref().unwrap_or("N/A")
);
println!(" Handle: {}", network.handle.as_deref().unwrap_or("N/A"));
}