Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8971807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:03:12+00:00 2026-06-15T18:03:12+00:00

this is my class that i want to return my machine network interfaces collection.

  • 0

this is my class that i want to return my machine network interfaces collection.
i choose to return IEnumerable and i dont know how to do it (i am a new developer).
or maybee there is batter way to build my class ?

public class NetworkAdapter
{
    string _name;
    string _id;        
    string _description;
    string _ipAddress;
    string _gatewayIpAddress;
    string _speed;
    string _networkInterfaceType;
    string _macAddress;

    public IEnumerable<NetworkAdapter> getAdapterInfo()
    {
        foreach (var adapter in NetworkInterface.GetAllNetworkInterfaces())
        {
            //fetch network configuration properties
            var properties = adapter.GetIPProperties();
            foreach (var uniCast in properties.UnicastAddresses)
            {
                //ignore loop-back addresses & IPv6 internet protocol family
                if (!IPAddress.IsLoopback(uniCast.Address) 
                    && uniCast.Address.AddressFamily != AddressFamily.InterNetworkV6) 
                {
                    _name = adapter.Name;
                    _id = adapter.Id;
                    _description = adapter.Description;
                    _ipAddress = uniCast.Address.ToString();
                    _networkInterfaceType = adapter.NetworkInterfaceType.ToString();
                    _speed = adapter.Speed.ToString("#,##0");

                    _macAddress = adapter.GetPhysicalAddress().ToString();

                    var gatewayAddresses = adapter.GetIPProperties().GatewayAddresses;
                    foreach (var gatewayAddress in gatewayAddresses)
                    {
                        _gatewayIpAddress = gatewayAddress.Address.ToString();
                    }
                }
            }
        }

        yield return new NetworkAdapter att;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:03:13+00:00Added an answer on June 15, 2026 at 6:03 pm

    You could use linq:

    return from adapter in NetworkInterface.GetAllNetworkInterfaces()
           from uniCast in adapter.GetIPProperties().UnicastAddresses
           where !IPAddress.IsLoopback(uniCast.Address) && uniCast.Address.AddressFamily != AddressFamily.InterNetworkV6
           let lastGatewayAddress = adapter.GetIPProperties().GatewayAddresses.LastOrDefault()
           select new NetworkAdapter
           {
               _name = adapter.Name,
               _id = adapter.Id,
               _description = adapter.Description,
               _ipAddress = uniCast.Address.ToString(),
               _networkInterfaceType = adapter.NetworkInterfaceType.ToString(),
               _speed = adapter.Speed.ToString("#,##0"),
               _macAddress = adapter.GetPhysicalAddress().ToString(),
               _gatewayIpAddress = lastGatewayAddress == null ? null : lastGatewayAddress.Address.ToString()
           };
    

    It’s not clear what you’re trying to do with the gateway addresses. At the moment it looks like you want the last one, although you might want to join them into a single string instead. In that case you can use:

    _gatewayIpAddress = string.Join(" ", adapater.GetIPProperties().GatewayAddresses.Select(a => a.Address));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this class that exposes an IEnumerable<Record> as follows (implementation details left out):
I want to create a new class that is a special type of string.
I have class that looks like this: class A { public: class variables_map vm
I wrote this class that draws a animated progress with a circle (it draws
I have this class that have a function to load other classes and create
I've written this class that returns feed updates, but am thinking it can be
I have this class that contains vars for db connection; Imports Microsoft.VisualBasic Imports System.Data.SqlClient
I have this class that has many class members, and a lot of different
I have a class that contains this class method: def self.get_event_record(row, participant) event =
Assume I have a class that looks like this: class Sample { public string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.