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