Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
Dns Class
Dns Methods

  Switch on low bandwidth view
Members FilterMembers Filter
Frameworks FilterFrameworks Filter
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
Dns..::.GetHostEntry Method

Resolves a host name or IP address to an IPHostEntry instance.

  NameDescription
Public methodStatic memberSupported by the .NET Compact FrameworkGetHostEntry(IPAddress) Resolves an IP address to an IPHostEntry instance.
Public methodStatic memberSupported by the .NET Compact FrameworkGetHostEntry(String) Resolves a host name or IP address to an IPHostEntry instance.
Top
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Get the full host name      Niels Grove-Rasmussen ... Thomas Lee   |   Edit   |   Show History

To get the full name of a host with all domain names you can use this methods and look at the HostName property of the result:

PS > [System.Net.Dns]::GetHostEntry('myserver').HostName
myserver.sqladmin.lan


FYI - This example is using PowerShell (and for this to work "myserver" has to exist in DNS)

GetHostEntry Method sample using PowerShell      Thomas Lee   |   Edit   |   Show History
<#
.SYNOPSIS
    Demonstrates use of the GetHostEntry method of System.Net.DNS Class
.DESCRIPTION
    This script is a an MSDN sample, using PowerShell
.NOTES
    File Name  : Get-HostEntry.ps1
    Author     : Thomas Lee - tfl@psp.co.uk
    Requires   : PowerShell V2 CTP3
.LINK
    Sample posted to:
        http://www.pshscripts.blogspot.com
 Original MSDN sample at:
        http://msdn.microsoft.com/en-us/library/system.net.dns.gethostentry.aspx
.EXAMPLE
    PSH [C:\foo]: .\Get-HostEntry.ps1'
    Host Name    : Cookham8.cookham.net
    Alias        :
    Address      : fe80::d8ed:afe2:2a97:a596%14
    Address      : fe80::3953:f67b:2f1c:1323%10
    Address      : 10.10.1.120
    Address      : 10.10.1.115
.PARAM HostName
    The name of the host to search for - the default is "localhost"
#>
param (
[string] $HostName = "localhost"
)
###
# Start of Script
###

#Get Host details
$hostentrydetails = [System.Net.Dns]::GetHostEntry($hostname)
  
# Print details:
"Host Name : {0}" -f $hostentrydetails.HostName
foreach ($alias in $hostentrydetails.alises) {
"Alias : {0}" -f $alias
}
foreach ($addr in $hostentrydetails.addresslist) {
"Address : {0}" -f $Addr.ipaddresstostring
}

# End of script
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker