Wednesday, June 8, 2016

DNS Scripts - Powershell


This script just gets and displays host details returned by GetHostByName.

     $hostInfo = [system.net.Dns]::GetHostByName("www.google.com");
     $hostinfo | fl * -force














This script just gets IP address of remote computer

Demonstrates use of the GetHostIP method of System.Net.DNS Class

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
}







There is another way to get DNS host Entries,

###
# Start of Script
###

# Convert $hostaddres to IPaddress class. 

# Create one for next call
$HostIp = [System.Net.IPAddress]::Parse("127.0.0.1")
if (! ([system.Net.IPAddress]::TryParse($hostaddress, [ref] $HostIP))) {"Not valid IP address"; return}

# Get Host info
$hostentrydetails = [System.Net.Dns]::GetHostEntry($HostIP)

# 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


No comments:

Post a Comment

Windows Server 2016 Key Features and License Prospects

If you are planning to move to Windows 2016 and looking for benefits, I have listed down below : Why Windows Server 2016? ·     ...