views:

24

answers:

1

I tried every trick in the book, creating a new object, instantiating it (even tho it says i can't) and just trying to create a reference to use it, and then also trying to call the .Address value inside it while using it like i would use a shared member (without instantiation) and nothing is working, msdn sample/help is useless... i even tried inheriting it and useing it like that, none of them worked, i am sure i am missing something, can anyone give me some code samples? here is the msdn docs on it to to give you an overview...

http://msdn.microsoft.com/en-us/library/system.net.networkinformation.gatewayipaddressinformation.aspx

although i like vb.net more i can read and coded in both c# and vb.net so either will be fine.

thanks:)

an aside: if anyone is wondering why, im just trying to get my routers name/label from a pc as shown here... http://stackoverflow.com/questions/3839189/how-to-get-router-name-ip-as-shown-in-windows-network-tab-in-code

+2  A: 

From MSDN:

  • In brief, you call NetworkInterface.GetAllNetworkInterfaces() to get a set of adapters.
  • On one of those adapters, get adapter.GetIPProperties().GatewayAddresses.
  • Each element of the GatewayAddresses is a GatewayIPAddressInformation.

public static void DisplayGatewayAddresses()
{
    Console.WriteLine("Gateways");
    NetworkInterface[] adapters  = NetworkInterface.GetAllNetworkInterfaces();
    foreach (NetworkInterface adapter in adapters)
    {
        IPInterfaceProperties adapterProperties = adapter.GetIPProperties();
        GatewayIPAddressInformationCollection addresses = adapterProperties.GatewayAddresses;
        if (addresses.Count >0)
        {
            Console.WriteLine(adapter.Description);
            foreach (GatewayIPAddressInformation address in addresses)
            {
                Console.WriteLine("  Gateway Address ......................... : {0}", 
                    address.Address.ToString());
            }
            Console.WriteLine();
        }
    }
}
abelenky
ahh, thanks, i have been looping through this actually without realizing the type (thanks to implicit declaration lol) looking for the elusive 'router name' that i've been looking for the last 3 days now... thank you...
Erx_VB.NExT.Coder
ps: i am looking on how to get router name of basic/user SOHO router as here, but can't find it in networkInterface class... http://stackoverflow.com/questions/3839189/how-to-get-router-name-ip-as-shown-in-windows-network-tab-in-code
Erx_VB.NExT.Coder