.NET Framework Class Library
Dns..::.GetHostEntry Method

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

Overload List

  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
See Also

Reference

Tags :


Community Content

Thomas Lee
Get the full host name

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)


Thomas Lee
GetHostEntry Method sample using PowerShell
<#
.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

Page view tracker