Finding IP addresses of local servers

I would like to get the IP addresses of a server (or servers) on a local network dynamically. How to get these IP addresses?


Update with the code from the answer:

// Query for all the enabled network adapters ManagementObjectSearcher objSearcher = new ManagementObjectSearcher( "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled='TRUE'"); ManagementObjectCollection objCollection = objSearcher.Get(); // Loop through all available network interfaces foreach (ManagementObject obj in objCollection) { // List all IP addresses of the current network interface string[] AddressList = (string[])obj["IPAddress"]; foreach (string Address in AddressList) { MessageBox.Show(Address); } } 

source code

I use this code, but it only returns my own IP address of the PC, and not all IP addresses on the network.

+4
source share
3 answers

This can be quite complicated, depending on the network configuration. If it is only a Windows network and the account on which the application is running, as well as administrator rights, it will be a little easier.

The best way would be to request your PDC (Primary Domain Controller). Check the System.DirectoryServices.ActiveDirectory namespace.

If I remember correctly, you can use LDAP to query the domain controller - as long as the PDC is configured correctly! I found this LDAP query that can help you:

"(objectCategory = computer) (| (operating system = Windows Server *) (operating system = Windows 2000 server))))))

Of course, this will only be requested by Windows 2000 servers - you should be able to change as needed.

Check out the following links:

http://www.google.co.uk/search?gcx=c&sourceid=chrome&ie=UTF-8&q=c%23+ldap+query

+1
source

This will allow you to get the IP address of the machine by name. Is this what you are looking for?

0
source

You have considered a discovery protocol such as Apple Bonjour (Zeroconf). http://en.wikipedia.org

0
source

Source: https://habr.com/ru/post/1340830/


All Articles