We are developing a client monitoring network application.
We would require IP addresses of all the computers in the network.

how do we retrieve these IP addresses ?
I have already seen some code that makes use of unmanaged C++ or WinAPI.
But I would prefer C# code (ofcourse). I went through some System.Net classes like Dns; but could not crack a way through.

Could anyone provide me some hints to my question?

Dani AI

Generated

— two practical options, depending on control and permissions: install a small agent on every client that periodically reports its IP/hostname (most accurate and resilient to firewalls/NAT), or perform discovery from one central host (scan + resolve). ’s web-server trick only gives you the HTTP client IP (useful for web apps, not for whole-LAN discovery). ’s linked snippet points in the right direction for local enumeration; the steps below expand that into a robust plan.

Enumerate local interfaces first (to learn which subnets to scan). Example: use System.Net.NetworkInformation to list active adapters and their IPv4 addresses and masks, skipping loopback/down interfaces.

using System;
using System.Net.NetworkInformation;
using System.Net.Sockets;

foreach (var nic in NetworkInterface.GetAllNetworkInterfaces())
{
    if (nic.OperationalStatus != OperationalStatus.Up) continue;
    foreach (var uni in nic.GetIPProperties().UnicastAddresses)
    {
        if (uni.Address.AddressFamily == AddressFamily.InterNetwork)
            Console.WriteLine($"{nic.Name} - {uni.Address} / {uni.IPv4Mask}");
    }
}

This gives you the IP + mask to compute the CIDR range for that interface. (learn.microsoft.com)

For discovery use a parallel ping sweep (async pings with limited concurrency), collect addresses that reply, then optionally do a reverse lookup to get hostnames. Use Ping.SendPingAsync for scalable async pings and Dns.GetHostEntry for name resolution. If ICMP is blocked, try a TCP connect to a common port or use the reverse-DNS results you can obtain from your DNS/DHCP/AD infrastructure instead of relying on pings. (learn.microsoft.com)

If you need MACs or devices on the same L2 segment, query the ARP table or call the OS SendARP API; for Windows-only inventory you can query remote machines with WMI (requires credentials and firewall access). Each method has tradeoffs: scanning can be noisy and slow, WMI/AD requires privileges, and ARP only works on the local subnet. (learn.microsoft.com)

Checklist: pick agent vs. scan; enumerate local subnets; perform parallel, rate‑limited discovery; fall back to AD/DHCP/WMI where available; handle ICMP/firewall failures (TCP/ARP/WMI).

Recommended Answers

All 2 Replies

i do this to get the current computer maybe look for something like this. Dim IPAddress as String = Request.ServerVariables.Get("REMOTE_ADDR") that is vb, c# is almost the same.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.