Prix
Prix

Reputation: 19528

Get current IP from adapter name?

I need to get the current IP from a adapter by name, I know how to find out the information about that given adapter but not if that can be used to get the IP of that adapter:

foreach (NetworkInterface adapter in networks)
{
    if (adapter.Name == "DataServer")
        break;
}

The adapater is named "DataServer" now I would like to know if there is a way to use that information to grab the actual IP address that adapter is assiged with without using the internet and with a way that I can assure it is connected to the given adapter name.

Or if there is a different way of doing this where I can get the IP by adapter name.

Upvotes: 0

Views: 226

Answers (1)

SLaks
SLaks

Reputation: 887195

Call

adapter.GetIPProperties().UnicastAddresses.Single(a => a.Address.AddressFamily == AddressFamily.InterNetwork).Address

Upvotes: 1

Related Questions