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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Oakrey.Network.Tools" Version="2.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Oakrey.Network.Tools" Version="2.0.4" />
                    
Directory.Packages.props
<PackageReference Include="Oakrey.Network.Tools" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Oakrey.Network.Tools --version 2.0.4
                    
#r "nuget: Oakrey.Network.Tools, 2.0.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Oakrey.Network.Tools@2.0.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Oakrey.Network.Tools&version=2.0.4
                    
Install as a Cake Addin
#tool nuget:?package=Oakrey.Network.Tools&version=2.0.4
                    
Install as a Cake Tool

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 -a command 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.Reactive 6.1.0 (direct dependency, included transitively)
  • ARP class requires Windows (arp command must be available on PATH)

Installation

.NET CLI

dotnet add package Oakrey.Network.Tools

Package Manager Console

Install-Package Oakrey.Network.Tools

NuGet Package Manager

  1. Open Visual Studio.
  2. Go to Tools > NuGet Package Manager > Manage NuGet Packages for Solution.
  3. Search for Oakrey.Network.Tools and 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

  • ARP shells out to the OS arp command. It is Windows-only and has no equivalent for Linux or macOS. Cross-platform callers should guard with RuntimeInformation.IsOSPlatform(OSPlatform.Windows).
  • TrafficMonitor starts sampling immediately on construction. Always dispose it to stop the background Observable.Timer subscription and release the BehaviorSubject.
  • NetworkDeviceInfo implements INotifyPropertyChanged. MacAddress, Name, and Type notify on change, making the class safe to bind directly in a WPF DataGrid or similar.
  • MacAddress, Name, and Type all default to "Unresolved". Resolution is opt-in via ResolveMacAddressAndType() and ResolveName(CancellationToken) to avoid blocking the scan path.
  • NetworkInfo.GetActiveNetworkInterface() throws InvalidOperationException if zero or more than one physical up interface is found. Use GetActiveNetworkInterfaces() directly when running on machines with multiple NICs.

License

MIT - Copyright (c) Oakrey 2016-present

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last Updated
2.0.4 116 5/22/2026
2.0.3 100 5/15/2026
2.0.2 150 2/2/2026
2.0.1 125 2/2/2026
2.0.0 446 11/18/2025
1.0.0 344 4/17/2025