none
get domain names RRS feed

  • Question

  • Is there a way to get all the domain in network/lan? 

    All our workstations and servers are connected on same network but separated only by ip and subnets and different domain names.

    Any help is appreciated.
    Tuesday, January 13, 2009 4:43 PM

Answers

  •  Something for you to play with:

            public void getLocalCompInfo ( )  
            {  
                IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties ( );  
                Console.WriteLine ( "Computer name: {0}", properties.HostName );  
                Console.WriteLine ( "Domain name:   {0}", properties.DomainName );  
                Console.WriteLine ( "Node type:     {0:f}", properties.NodeType );  
                Console.WriteLine ( "DHCP scope:    {0}", properties.DhcpScopeName );  
                Console.WriteLine ( "WINS proxy?    {0}", properties.IsWinsProxy );  
            }                                               // getLocalCompInfo 
            public void ShowNetworkInterfaces ( )  
            {  
                // AsymmetricDsl The network interface uses an Asymmetric Digital Subscriber Line (ADSL).    
                // Atm The network interface uses asynchronous transfer mode (ATM) for data transmission.    
                // BasicIsdn The network interface uses a basic rate interface Integrated Services Digital Network (ISDN) connection. ISDN is a set of standards for data transmission over telephone lines.    
                // Ethernet The network interface uses an Ethernet connection. Ethernet is defined in IEEE standard 802.3.    
                // Ethernet3Megabit The network interface uses an Ethernet 3 megabit/second connection. This version of Ethernet is defined in IETF RFC 895.    
                // FastEthernetFx The network interface uses a Fast Ethernet connection over optical fiber. This type of connection is also known as 100BaseFX.    
                // FastEthernetT The network interface uses a Fast Ethernet connection. Fast Ethernet provides a data rate of 100 megabits per second, known as 100BaseT.    
                // Fddi The network interface uses a Fiber Distributed Data Interface (FDDI) connection. FDDI is a set of standards for data transmission on fiber optic lines in a local area network.    
                // GenericModem The network interface uses a modem.    
                // GigabitEthernet The network interface uses a gigabit Ethernet connection.   
                // HighPerformanceSerialBus The network interface uses a High Performance Serial Bus.    
                // IPOverAtm The network interface uses Internet Protocol (IP) in combination with asynchronous transfer mode (ATM) for data transmission.    
                // Isdn The network interface uses a connection configured for ISDN and the X.25 protocol. X.25 allows computers on public networks to communicate using an intermediary computer.    
                // Loopback The network interface is a loopback adapter. Such interfaces are used primarily for testing; no traffic is sent.    
                // MultiRateSymmetricDsl The network interface uses a Multirate Digital Subscriber Line.    
                // Ppp The network interface uses a Point-To-Point protocol (PPP) connection. PPP is a protocol for data transmission using a serial device.    
                // PrimaryIsdn The network interface uses a primary rate interface Integrated Services Digital Network (ISDN) connection. ISDN is a set of standards for data transmission over telephone lines.    
                // RateAdaptDsl The network interface uses a Rate Adaptive Digital Subscriber Line (RADSL).    
                // Slip The network interface uses a Serial Line Internet Protocol (SLIP) connection. SLIP is defined in IETF RFC 1055.    
                // SymmetricDsl The network interface uses a Symmetric Digital Subscriber Line (SDSL).    
                // TokenRing The network interface uses a Token-Ring connection. Token-Ring is defined in IEEE standard 802.5.    
                // Tunnel The network interface uses a tunnel connection.    
                // Unknown The interface type is not known.    
                // VeryHighSpeedDsl The network interface uses a Very High Data Rate Digital Subscriber Line (VDSL).    
                // Wireless80211 The network interface uses a wireless LAN connection (IEEE 802.11 standard).    
     
     
                IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties ( );  
                NetworkInterface[ ] nics = NetworkInterface.GetAllNetworkInterfaces ( );  
                Console.WriteLine ( "Interface information for {0}.{1}     ", computerProperties.HostName, computerProperties.DomainName );  
                if ( nics == null || nics.Length < 1 )  
                {  
                    Console.WriteLine ( "  No network interfaces found." );  
                    return;  
                }  
                Console.WriteLine ( "  Number of interfaces .................... : {0}", nics.Length );  
                foreach ( NetworkInterface adapter in nics )  
                {  
                    IPInterfaceProperties properties = adapter.GetIPProperties ( );  
                    Console.WriteLine ( );  
                    Console.WriteLine ( adapter.Description );  
                    Console.WriteLine ( String.Empty.PadLeft ( adapter.Description.Length, '=' ) );  
                    Console.WriteLine ( "  Interface type .......................... : {0}", adapter.NetworkInterfaceType );  
                    Console.WriteLine ( "  Physical Address ........................ : {0}", adapter.GetPhysicalAddress ( ).ToString ( ) );  
                    Console.WriteLine ( "  Operational status ...................... : {0}", adapter.OperationalStatus );  
                    string versions = "";  
     
                    // Create a display string for the supported IP versions.  
                    if ( adapter.Supports ( NetworkInterfaceComponent.IPv4 ) )  
                    {  
                        versions = "IPv4";  
                    }  
                    if ( adapter.Supports ( NetworkInterfaceComponent.IPv6 ) )  
                    {  
                        if ( versions.Length > 0 )  
                        {  
                            versions += " ";  
                        }  
                        versions += "IPv6";  
                    }  
                    Console.WriteLine ( "  IP version .............................. : {0}", versions );  
                    ShowIPAddresses ( properties );  
                    // The following information is not useful for loopback adapters.  
                    if ( adapter.NetworkInterfaceType == NetworkInterfaceType.Loopback )  
                    {  
                        continue;  
                    }  
                    Console.WriteLine ( "  DNS suffix .............................. : {0}", properties.DnsSuffix );  
                    string label;  
                    if ( adapter.Supports ( NetworkInterfaceComponent.IPv4 ) )  
                    {  
                        IPv4InterfaceProperties ipv4 = properties.GetIPv4Properties ( );  
                        Console.WriteLine ( "  MTU...................................... : {0}", ipv4.Mtu );  
                        if ( ipv4.UsesWins )  
                        {  
                            IPAddressCollection winsServers = properties.WinsServersAddresses;  
                            if ( winsServers.Count > 0 )  
                            {  
                                label = "  WINS Servers ............................ :";  
                                Console.WriteLine ( label, winsServers.Count );  
                                IEnumerator<IPAddress> en = winsServers.GetEnumerator ( );  
                                Console.WriteLine ( "IEnumerator : {0}", en.MoveNext ( ) );  
                            }  
                        }  
                    }  
     
                    Console.WriteLine ( "  DNS enabled ............................. : {0}", properties.IsDnsEnabled );  
                    Console.WriteLine ( "  Dynamically configured DNS .............. : {0}", properties.IsDynamicDnsEnabled );  
                    Console.WriteLine ( "  Receive Only ............................ : {0}", adapter.IsReceiveOnly );  
                    Console.WriteLine ( "  Multicast ............................... : {0}", adapter.SupportsMulticast );  
                    SecurityAndDebug showAndDebug = new SecurityAndDebug ( );  
                    showAndDebug.ShowInterfaceStatistics ( adapter );  
                    Console.WriteLine ( );  
                }  
            }                                               // ShowNetworkInterfaces  
     
            public void DisplayIPv4NetworkInterfaces ( )  
            {  
                NetworkInterface[ ] nics = NetworkInterface.GetAllNetworkInterfaces ( );  
                IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties ( );  
                Console.WriteLine ( "IPv4 interface information for {0}.{1}", properties.HostName, properties.DomainName );  
                foreach ( NetworkInterface adapter in nics )  
                {  
                    // Only display informatin for interfaces that support IPv4.  
                    if ( adapter.Supports ( NetworkInterfaceComponent.IPv4 ) == false )  
                    {  
                        continue;  
                    }  
                    Console.WriteLine ( );  
                    Console.WriteLine ( adapter.Description );  
                    // Underline the description.  
                    Console.WriteLine ( String.Empty.PadLeft ( adapter.Description.Length, '=' ) );  
                    IPInterfaceProperties adapteradapterProperties = adapter.GetIPProperties ( );  
                    // Try to get the IPv4 interface properties.  
                    IPv4InterfaceProperties p = adapterProperties.GetIPv4Properties ( );  
                    if ( p == null )  
                    {  
                        Console.WriteLine ( "No IPv4 information is available for this interface." );  
                        continue;  
                    }  
                    // Display the IPv4 specific data.  
                    Console.WriteLine ( "  Index ............................. : {0}", p.Index );  
                    Console.WriteLine ( "  MTU ............................... : {0}", p.Mtu );  
                    Console.WriteLine ( "  APIPA active....................... : {0}", p.IsAutomaticPrivateAddressingActive );  
                    Console.WriteLine ( "  APIPA enabled...................... : {0}", p.IsAutomaticPrivateAddressingEnabled );  
                    Console.WriteLine ( "  Forwarding enabled................. : {0}", p.IsForwardingEnabled );  
                    Console.WriteLine ( "  Uses WINS ......................... : {0}", p.UsesWins );  
                }  
            }                                               // DisplayIPv4NetworkInterfaces  
     

    AlexB
    • Marked as answer by omicron77 Tuesday, January 13, 2009 5:19 PM
    Tuesday, January 13, 2009 5:00 PM
  •  Some more.
            public void DisplayTypeAndAddress ( )  
            {  
                IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties ( );  
                NetworkInterface[ ] nics = NetworkInterface.GetAllNetworkInterfaces ( );  
                Console.WriteLine ( "Interface information for {0}.{1}     ",  
                        computerProperties.HostName, computerProperties.DomainName );  
                foreach ( NetworkInterface adapter in nics )  
                {  
                    IPInterfaceProperties properties = adapter.GetIPProperties ( );  
                    Console.WriteLine ( adapter.Description );  
                    Console.WriteLine ( String.Empty.PadLeft ( adapter.Description.Length, '=' ) );  
                    Console.WriteLine ( "  Interface type .......................... : {0}", adapter.NetworkInterfaceType );  
                    Console.WriteLine ( "  Physical Address ........................ : {0}", adapter.GetPhysicalAddress ( ).ToString ( ) );  
                    Console.WriteLine ( "  Is receive only.......................... : {0}", adapter.IsReceiveOnly );  
                    Console.WriteLine ( "  Multicast................................ : {0}", adapter.SupportsMulticast );  
                }  
            }                                               // DisplayTypeAndAddress  
     

    AlexB
    • Marked as answer by omicron77 Tuesday, January 13, 2009 5:19 PM
    Tuesday, January 13, 2009 5:01 PM
  •  Depending on the OS you could also use Powershell...  

    [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Domains

    ...Powershell can be executed from C#.  http://www.codeproject.com/KB/cs/HowToRunPowerShell.aspx

    Regards,

    Jeff

    • Marked as answer by omicron77 Tuesday, January 13, 2009 5:21 PM
    Tuesday, January 13, 2009 5:09 PM
  • JeffWask said:

     Depending on the OS you could also use Powershell...  

    [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Domains

    ...Powershell can be executed from C#.  http://www.codeproject.com/KB/cs/HowToRunPowerShell.aspx

    Regards,

    Jeff



    Adding a reference to System.DirectoryServices will allow you to use the Forest class from within C#.  No need to move to PowerShell to use it. The syntax in C# would look like this:

    System.DirectoryServices.ActiveDirectory.Forest.GetCurrentForest().Domains

    Forest is a .NET class.
    David Morton - http://blog.davemorton.net/
    • Marked as answer by omicron77 Tuesday, January 13, 2009 5:29 PM
    Tuesday, January 13, 2009 5:22 PM
    Moderator

All replies

  •  Something for you to play with:

            public void getLocalCompInfo ( )  
            {  
                IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties ( );  
                Console.WriteLine ( "Computer name: {0}", properties.HostName );  
                Console.WriteLine ( "Domain name:   {0}", properties.DomainName );  
                Console.WriteLine ( "Node type:     {0:f}", properties.NodeType );  
                Console.WriteLine ( "DHCP scope:    {0}", properties.DhcpScopeName );  
                Console.WriteLine ( "WINS proxy?    {0}", properties.IsWinsProxy );  
            }                                               // getLocalCompInfo 
            public void ShowNetworkInterfaces ( )  
            {  
                // AsymmetricDsl The network interface uses an Asymmetric Digital Subscriber Line (ADSL).    
                // Atm The network interface uses asynchronous transfer mode (ATM) for data transmission.    
                // BasicIsdn The network interface uses a basic rate interface Integrated Services Digital Network (ISDN) connection. ISDN is a set of standards for data transmission over telephone lines.    
                // Ethernet The network interface uses an Ethernet connection. Ethernet is defined in IEEE standard 802.3.    
                // Ethernet3Megabit The network interface uses an Ethernet 3 megabit/second connection. This version of Ethernet is defined in IETF RFC 895.    
                // FastEthernetFx The network interface uses a Fast Ethernet connection over optical fiber. This type of connection is also known as 100BaseFX.    
                // FastEthernetT The network interface uses a Fast Ethernet connection. Fast Ethernet provides a data rate of 100 megabits per second, known as 100BaseT.    
                // Fddi The network interface uses a Fiber Distributed Data Interface (FDDI) connection. FDDI is a set of standards for data transmission on fiber optic lines in a local area network.    
                // GenericModem The network interface uses a modem.    
                // GigabitEthernet The network interface uses a gigabit Ethernet connection.   
                // HighPerformanceSerialBus The network interface uses a High Performance Serial Bus.    
                // IPOverAtm The network interface uses Internet Protocol (IP) in combination with asynchronous transfer mode (ATM) for data transmission.    
                // Isdn The network interface uses a connection configured for ISDN and the X.25 protocol. X.25 allows computers on public networks to communicate using an intermediary computer.    
                // Loopback The network interface is a loopback adapter. Such interfaces are used primarily for testing; no traffic is sent.    
                // MultiRateSymmetricDsl The network interface uses a Multirate Digital Subscriber Line.    
                // Ppp The network interface uses a Point-To-Point protocol (PPP) connection. PPP is a protocol for data transmission using a serial device.    
                // PrimaryIsdn The network interface uses a primary rate interface Integrated Services Digital Network (ISDN) connection. ISDN is a set of standards for data transmission over telephone lines.    
                // RateAdaptDsl The network interface uses a Rate Adaptive Digital Subscriber Line (RADSL).    
                // Slip The network interface uses a Serial Line Internet Protocol (SLIP) connection. SLIP is defined in IETF RFC 1055.    
                // SymmetricDsl The network interface uses a Symmetric Digital Subscriber Line (SDSL).    
                // TokenRing The network interface uses a Token-Ring connection. Token-Ring is defined in IEEE standard 802.5.    
                // Tunnel The network interface uses a tunnel connection.    
                // Unknown The interface type is not known.    
                // VeryHighSpeedDsl The network interface uses a Very High Data Rate Digital Subscriber Line (VDSL).    
                // Wireless80211 The network interface uses a wireless LAN connection (IEEE 802.11 standard).    
     
     
                IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties ( );  
                NetworkInterface[ ] nics = NetworkInterface.GetAllNetworkInterfaces ( );  
                Console.WriteLine ( "Interface information for {0}.{1}     ", computerProperties.HostName, computerProperties.DomainName );  
                if ( nics == null || nics.Length < 1 )  
                {  
                    Console.WriteLine ( "  No network interfaces found." );  
                    return;  
                }  
                Console.WriteLine ( "  Number of interfaces .................... : {0}", nics.Length );  
                foreach ( NetworkInterface adapter in nics )  
                {  
                    IPInterfaceProperties properties = adapter.GetIPProperties ( );  
                    Console.WriteLine ( );  
                    Console.WriteLine ( adapter.Description );  
                    Console.WriteLine ( String.Empty.PadLeft ( adapter.Description.Length, '=' ) );  
                    Console.WriteLine ( "  Interface type .......................... : {0}", adapter.NetworkInterfaceType );  
                    Console.WriteLine ( "  Physical Address ........................ : {0}", adapter.GetPhysicalAddress ( ).ToString ( ) );  
                    Console.WriteLine ( "  Operational status ...................... : {0}", adapter.OperationalStatus );  
                    string versions = "";  
     
                    // Create a display string for the supported IP versions.  
                    if ( adapter.Supports ( NetworkInterfaceComponent.IPv4 ) )  
                    {  
                        versions = "IPv4";  
                    }  
                    if ( adapter.Supports ( NetworkInterfaceComponent.IPv6 ) )  
                    {  
                        if ( versions.Length > 0 )  
                        {  
                            versions += " ";  
                        }  
                        versions += "IPv6";  
                    }  
                    Console.WriteLine ( "  IP version .............................. : {0}", versions );  
                    ShowIPAddresses ( properties );  
                    // The following information is not useful for loopback adapters.  
                    if ( adapter.NetworkInterfaceType == NetworkInterfaceType.Loopback )  
                    {  
                        continue;  
                    }  
                    Console.WriteLine ( "  DNS suffix .............................. : {0}", properties.DnsSuffix );  
                    string label;  
                    if ( adapter.Supports ( NetworkInterfaceComponent.IPv4 ) )  
                    {  
                        IPv4InterfaceProperties ipv4 = properties.GetIPv4Properties ( );  
                        Console.WriteLine ( "  MTU...................................... : {0}", ipv4.Mtu );  
                        if ( ipv4.UsesWins )  
                        {  
                            IPAddressCollection winsServers = properties.WinsServersAddresses;  
                            if ( winsServers.Count > 0 )  
                            {  
                                label = "  WINS Servers ............................ :";  
                                Console.WriteLine ( label, winsServers.Count );  
                                IEnumerator<IPAddress> en = winsServers.GetEnumerator ( );  
                                Console.WriteLine ( "IEnumerator : {0}", en.MoveNext ( ) );  
                            }  
                        }  
                    }  
     
                    Console.WriteLine ( "  DNS enabled ............................. : {0}", properties.IsDnsEnabled );  
                    Console.WriteLine ( "  Dynamically configured DNS .............. : {0}", properties.IsDynamicDnsEnabled );  
                    Console.WriteLine ( "  Receive Only ............................ : {0}", adapter.IsReceiveOnly );  
                    Console.WriteLine ( "  Multicast ............................... : {0}", adapter.SupportsMulticast );  
                    SecurityAndDebug showAndDebug = new SecurityAndDebug ( );  
                    showAndDebug.ShowInterfaceStatistics ( adapter );  
                    Console.WriteLine ( );  
                }  
            }                                               // ShowNetworkInterfaces  
     
            public void DisplayIPv4NetworkInterfaces ( )  
            {  
                NetworkInterface[ ] nics = NetworkInterface.GetAllNetworkInterfaces ( );  
                IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties ( );  
                Console.WriteLine ( "IPv4 interface information for {0}.{1}", properties.HostName, properties.DomainName );  
                foreach ( NetworkInterface adapter in nics )  
                {  
                    // Only display informatin for interfaces that support IPv4.  
                    if ( adapter.Supports ( NetworkInterfaceComponent.IPv4 ) == false )  
                    {  
                        continue;  
                    }  
                    Console.WriteLine ( );  
                    Console.WriteLine ( adapter.Description );  
                    // Underline the description.  
                    Console.WriteLine ( String.Empty.PadLeft ( adapter.Description.Length, '=' ) );  
                    IPInterfaceProperties adapteradapterProperties = adapter.GetIPProperties ( );  
                    // Try to get the IPv4 interface properties.  
                    IPv4InterfaceProperties p = adapterProperties.GetIPv4Properties ( );  
                    if ( p == null )  
                    {  
                        Console.WriteLine ( "No IPv4 information is available for this interface." );  
                        continue;  
                    }  
                    // Display the IPv4 specific data.  
                    Console.WriteLine ( "  Index ............................. : {0}", p.Index );  
                    Console.WriteLine ( "  MTU ............................... : {0}", p.Mtu );  
                    Console.WriteLine ( "  APIPA active....................... : {0}", p.IsAutomaticPrivateAddressingActive );  
                    Console.WriteLine ( "  APIPA enabled...................... : {0}", p.IsAutomaticPrivateAddressingEnabled );  
                    Console.WriteLine ( "  Forwarding enabled................. : {0}", p.IsForwardingEnabled );  
                    Console.WriteLine ( "  Uses WINS ......................... : {0}", p.UsesWins );  
                }  
            }                                               // DisplayIPv4NetworkInterfaces  
     

    AlexB
    • Marked as answer by omicron77 Tuesday, January 13, 2009 5:19 PM
    Tuesday, January 13, 2009 5:00 PM
  •  Some more.
            public void DisplayTypeAndAddress ( )  
            {  
                IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties ( );  
                NetworkInterface[ ] nics = NetworkInterface.GetAllNetworkInterfaces ( );  
                Console.WriteLine ( "Interface information for {0}.{1}     ",  
                        computerProperties.HostName, computerProperties.DomainName );  
                foreach ( NetworkInterface adapter in nics )  
                {  
                    IPInterfaceProperties properties = adapter.GetIPProperties ( );  
                    Console.WriteLine ( adapter.Description );  
                    Console.WriteLine ( String.Empty.PadLeft ( adapter.Description.Length, '=' ) );  
                    Console.WriteLine ( "  Interface type .......................... : {0}", adapter.NetworkInterfaceType );  
                    Console.WriteLine ( "  Physical Address ........................ : {0}", adapter.GetPhysicalAddress ( ).ToString ( ) );  
                    Console.WriteLine ( "  Is receive only.......................... : {0}", adapter.IsReceiveOnly );  
                    Console.WriteLine ( "  Multicast................................ : {0}", adapter.SupportsMulticast );  
                }  
            }                                               // DisplayTypeAndAddress  
     

    AlexB
    • Marked as answer by omicron77 Tuesday, January 13, 2009 5:19 PM
    Tuesday, January 13, 2009 5:01 PM
  •  You can also find such information in TechNet Script Repositiry site. That will be VB scripting.
    AlexB
    Tuesday, January 13, 2009 5:02 PM
  • Tuesday, January 13, 2009 5:06 PM
  •  Depending on the OS you could also use Powershell...  

    [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Domains

    ...Powershell can be executed from C#.  http://www.codeproject.com/KB/cs/HowToRunPowerShell.aspx

    Regards,

    Jeff

    • Marked as answer by omicron77 Tuesday, January 13, 2009 5:21 PM
    Tuesday, January 13, 2009 5:09 PM
  • Thank you very much for the code you provide.  I will try to play with it.

    Tuesday, January 13, 2009 5:18 PM
  • JeffWask said:

     Depending on the OS you could also use Powershell...  

    [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Domains

    ...Powershell can be executed from C#.  http://www.codeproject.com/KB/cs/HowToRunPowerShell.aspx

    Regards,

    Jeff


    I will check this also sir.

    Thanks!
    Tuesday, January 13, 2009 5:21 PM
  • JeffWask said:

     Depending on the OS you could also use Powershell...  

    [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Domains

    ...Powershell can be executed from C#.  http://www.codeproject.com/KB/cs/HowToRunPowerShell.aspx

    Regards,

    Jeff



    Adding a reference to System.DirectoryServices will allow you to use the Forest class from within C#.  No need to move to PowerShell to use it. The syntax in C# would look like this:

    System.DirectoryServices.ActiveDirectory.Forest.GetCurrentForest().Domains

    Forest is a .NET class.
    David Morton - http://blog.davemorton.net/
    • Marked as answer by omicron77 Tuesday, January 13, 2009 5:29 PM
    Tuesday, January 13, 2009 5:22 PM
    Moderator
  • Hi

    Where found "SecurityAndDebug" Class??

    Thank you

    Tuesday, August 16, 2011 2:31 PM