Oakrey.Network.Tools
2.0.4
dotnet add package Oakrey.Network.Tools --version 2.0.4
NuGet\Install-Package Oakrey.Network.Tools -Version 2.0.4
<PackageReference Include="Oakrey.Network.Tools" Version="2.0.4" />
<PackageVersion Include="Oakrey.Network.Tools" Version="2.0.4" />
<PackageReference Include="Oakrey.Network.Tools" />
paket add Oakrey.Network.Tools --version 2.0.4
#r "nuget: Oakrey.Network.Tools, 2.0.4"
#:package Oakrey.Network.Tools@2.0.4
#addin nuget:?package=Oakrey.Network.Tools&version=2.0.4
#tool nuget:?package=Oakrey.Network.Tools&version=2.0.4
Oakrey.Network.Tools
Network utility library for .NET 10. Provides ARP table queries, IPv4/IPv6 string validation, NetworkInterface extension methods, active interface resolution, real-time per-second traffic statistics, and a bindable NetworkDeviceInfo model with async DNS and MAC resolution.
Features
ARP (ARP)
Shells out to the OS arp command and parses the output.
| Method | Signature | Description |
|---|---|---|
GetIPAddresses |
static List<NetworkDeviceInfo> |
Returns all entries from the ARP table |
GetMacAddress |
IPAddress extension ? string |
Returns MAC address for a specific IP |
GetAddressType |
IPAddress extension ? string |
Returns device/adapter type for a specific IP |
This class is Windows-only. It relies on the
arp -acommand available on Windows.
IP validation (IpValidation)
Extension methods on string.
| Method | Returns | Description |
|---|---|---|
IsIpV4(this string) |
bool |
Returns true if the string is a valid dotted-decimal IPv4 address |
IsIpV6(this string) |
bool |
Returns true if the string is a valid colon-separated hexadecimal IPv6 address |
Network interface extensions (NetworkInterfaceExtensions)
Extension methods on System.Net.NetworkInformation.NetworkInterface.
| Method | Returns | Description |
|---|---|---|
GetIPv4Addresses |
IEnumerable<IPAddress> |
Unicast IPv4 addresses assigned to the interface |
GetIPv6Addresses |
IEnumerable<IPAddress> |
Unicast IPv6 addresses assigned to the interface |
GetMacAddress |
string |
Formatted MAC address (AA:BB:CC:DD:EE:FF) |
GetDnsAddresses |
IEnumerable<IPAddress> |
DNS server addresses configured on the interface |
IsPhysical |
bool |
true if not loopback, tunnel, or virtual |
IsUp |
bool |
true if OperationalStatus == Up |
IsLoopback |
bool |
true if type is Loopback |
IsTunnel |
bool |
true if type is Tunnel |
Active interface resolution (NetworkInfo)
Static helpers using NetworkInterface.GetAllNetworkInterfaces() filtered to physical, up interfaces.
| Method | Returns | Description |
|---|---|---|
GetNetworkInterfaces |
IEnumerable<NetworkInterface> |
All interfaces on the machine |
GetActiveNetworkInterfaces |
List<NetworkInterface> |
Physical, up interfaces only |
GetActiveNetworkInterface() |
NetworkInterface |
Throws if zero or more than one active interface found |
GetActiveNetworkInterface(string name) |
NetworkInterface |
Throws KeyNotFoundException if not found |
GetActiveNetworkInterfaceIpAddress |
IPAddress |
First IPv4 address of the single active interface |
Traffic monitoring (TrafficMonitor, Traffic)
TrafficMonitor implements IObservable<Traffic> and IDisposable. It samples IPInterfaceStatistics every second using Observable.Timer and emits the delta.
public record Traffic(int TransmittedBytesPerSecond, int ReceivedBytesPerSecond);
| Member | Description |
|---|---|
TrafficMonitor(NetworkInterface) |
Starts sampling on the given interface immediately |
Subscribe(IObserver<Traffic>) |
Subscribe to per-second traffic updates |
Dispose() |
Stops the timer and releases the Rx subscription |
Network device info (NetworkDeviceInfo)
Bindable model (INotifyPropertyChanged) representing a discovered network device.
| Member | Type | Default | Description |
|---|---|---|---|
IpAddress |
IPAddress |
� | Set at construction |
PingReply |
PingReply? |
null |
Set when constructed from a PingReply |
MacAddress |
string |
"Unresolved" |
Populated by ResolveMacAddressAndType() |
Type |
string |
"Unresolved" |
Populated by ResolveMacAddressAndType() |
Name |
string |
"Unresolved" |
Populated by ResolveName(CancellationToken) |
ResolveMacAddressAndType() |
void |
� | Queries ARP for MAC and type; silently sets "Unresolved" on failure |
ResolveName(CancellationToken) |
Task |
� | DNS reverse-lookup via Dns.GetHostEntry |
Architecture
classDiagram
class ARP {
+List~NetworkDeviceInfo~ GetIPAddresses()$
+string GetMacAddress(IPAddress)
+string GetAddressType(IPAddress)
}
class IpValidation {
+bool IsIpV4(string)
+bool IsIpV6(string)
}
class NetworkInterfaceExtensions {
+IEnumerable~IPAddress~ GetIPv4Addresses(NetworkInterface)
+IEnumerable~IPAddress~ GetIPv6Addresses(NetworkInterface)
+string GetMacAddress(NetworkInterface)
+IEnumerable~IPAddress~ GetDnsAddresses(NetworkInterface)
+bool IsPhysical(NetworkInterface)
+bool IsUp(NetworkInterface)
}
class NetworkInfo {
+NetworkInterface GetActiveNetworkInterface()$
+List~NetworkInterface~ GetActiveNetworkInterfaces()$
+IPAddress GetActiveNetworkInterfaceIpAddress()$
}
class Traffic {
+int TransmittedBytesPerSecond
+int ReceivedBytesPerSecond
}
class TrafficMonitor {
+IDisposable Subscribe(IObserver~Traffic~)
+Dispose()
}
class NetworkDeviceInfo {
+IPAddress IpAddress
+PingReply? PingReply
+string MacAddress
+string Name
+string Type
+ResolveMacAddressAndType()
+Task ResolveName(CancellationToken)
}
TrafficMonitor --> Traffic : emits
ARP --> NetworkDeviceInfo : creates
NetworkInfo --> NetworkInterfaceExtensions : uses
TrafficMonitor --> NetworkInterfaceExtensions : uses
Requirements
- .NET 10 or higher
System.Reactive6.1.0 (direct dependency, included transitively)ARPclass requires Windows (arpcommand must be available onPATH)
Installation
.NET CLI
dotnet add package Oakrey.Network.Tools
Package Manager Console
Install-Package Oakrey.Network.Tools
NuGet Package Manager
- Open Visual Studio.
- Go to Tools > NuGet Package Manager > Manage NuGet Packages for Solution.
- Search for
Oakrey.Network.Toolsand click Install.
Example usage
Query the ARP table
List<NetworkDeviceInfo> devices = ARP.GetIPAddresses();
foreach (NetworkDeviceInfo device in devices)
{
Console.WriteLine($"{device.IpAddress} {device.MacAddress} {device.Type}");
}
Validate IP strings
bool v4 = "192.168.1.1".IsIpV4(); // true
bool v6 = "::1".IsIpV6(); // true
bool bad = "999.x.1.1".IsIpV4(); // false
Resolve a single device from its IP address
IPAddress target = IPAddress.Parse("192.168.1.1");
NetworkDeviceInfo device = new(target);
device.ResolveMacAddressAndType();
await device.ResolveName(CancellationToken.None);
Console.WriteLine($"Name: {device.Name} MAC: {device.MacAddress} Type: {device.Type}");
Get the active network interface and its addresses
NetworkInterface adapter = NetworkInfo.GetActiveNetworkInterface();
IEnumerable<IPAddress> ipv4 = adapter.GetIPv4Addresses();
string mac = adapter.GetMacAddress();
Monitor live traffic
NetworkInterface adapter = NetworkInfo.GetActiveNetworkInterface();
using TrafficMonitor monitor = new(adapter);
using IDisposable subscription = monitor.Subscribe(traffic =>
{
Console.WriteLine($"TX: {traffic.TransmittedBytesPerSecond} B/s RX: {traffic.ReceivedBytesPerSecond} B/s");
});
await Task.Delay(TimeSpan.FromSeconds(10));
Development notes
ARPshells out to the OSarpcommand. It is Windows-only and has no equivalent for Linux or macOS. Cross-platform callers should guard withRuntimeInformation.IsOSPlatform(OSPlatform.Windows).TrafficMonitorstarts sampling immediately on construction. Always dispose it to stop the backgroundObservable.Timersubscription and release theBehaviorSubject.NetworkDeviceInfoimplementsINotifyPropertyChanged.MacAddress,Name, andTypenotify on change, making the class safe to bind directly in a WPFDataGridor similar.MacAddress,Name, andTypeall default to"Unresolved". Resolution is opt-in viaResolveMacAddressAndType()andResolveName(CancellationToken)to avoid blocking the scan path.NetworkInfo.GetActiveNetworkInterface()throwsInvalidOperationExceptionif zero or more than one physical up interface is found. UseGetActiveNetworkInterfaces()directly when running on machines with multiple NICs.
License
MIT - Copyright (c) Oakrey 2016-present
- Repository: Azure DevOps
- NuGet: Oakrey.Network.Tools
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- System.Reactive (>= 6.1.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Oakrey.Network.Tools:
| Package | Downloads |
|---|---|
|
Oakrey.Network.IpScanner
Asynchronous IPv4 network scanner that pings an IpAddressRange and exposes discovered devices as IObservable<NetworkDeviceInfo>. Uses ICMP (System.Net.NetworkInformation.Ping) with configurable timeout, reports scan progress via IObservable<int> (remaining pings), and resolves each live host to its IP address, MAC address, hostname, and device type. Depends on Oakrey.Network.Abstractions and Oakrey.Network.Tools. |
GitHub repositories
This package is not used by any popular GitHub repositories.