Venkata Koppaka
Venkata Koppaka

Reputation: 461

How to get a list of IP Addresses in a Network

How to get a list of IP Addresses/hostnames in a Network using c#

Upvotes: 2

Views: 1566

Answers (3)

R. Martinho Fernandes
R. Martinho Fernandes

Reputation: 234644

I wrote a program that does exactly that. I have it at home :(

It uses the Ping and NetworkInterface classes, to find it through brute force.

I basically iterate through all interfaces, generate all addresses that are valid for the interface network mask, and ping them asynchronously.

It's simple but not perfect. If there are interfaces in the network that don't reply to pings, they won't be listed. This could be the case if there are firewalls active (like Windows Firewall which blocks pings by default).

Oh, yes, it's terribly exhaustive.

EDIT: Even though Mitch Wheat's answer is not what you asked, it reminded me you could use Dns to resolve the hostnames of all those addresses..

Upvotes: 2

Richard Whitty
Richard Whitty

Reputation: 41

Something to note however: By default, modern Windows systems do not respond to pings (e.g. XP with the firewall on), so the approach proposed won't work reliably.

The technique I use (albeit not on Windows or C#) is to ping the whole subnet, then look in the ARP cache (as the machines will still respond to ARP requests.)

Not sure how one would accomplish this in C# though.

Upvotes: 1

John Rasch
John Rasch

Reputation: 63485

CodeProject has a pretty crude way of achieving this using the DOS net view command:

http://www.codeproject.com/KB/IP/ipaddresses.aspx

Upvotes: 0

Related Questions