Skip to content

Instantly share code, notes, and snippets.

@Graham-Beer
Created May 17, 2016 20:43
Show Gist options
  • Save Graham-Beer/731975067e2a7f505b440b2ba934c1c2 to your computer and use it in GitHub Desktop.
Save Graham-Beer/731975067e2a7f505b440b2ba934c1c2 to your computer and use it in GitHub Desktop.
Get IP from Host / Host from IP
<#
.Details
Small function to find either IP address from Host or Host from IP
By G Beer
#>
Function Get-NetDetails {
[CmdletBinding(DefaultParameterSetName='ByIP')]
param (
[Parameter(Mandatory = $true, ParameterSetName = 'ByIP')]
[System.String]
$IP,
[Parameter(Mandatory = $true, ParameterSetName = 'ByHost')]
[System.String]
$HostName
)
switch ($PsCmdlet.ParameterSetName){
'ByIP' { Try {"HostName is: " + [system.net.dns]::GetHostByAddress($IP).hostname} Catch [exception] { $_ } }
'ByHost' { Try {"IP Address is: " + ([system.net.dns]::GetHostByName($HostName).AddressList).IPAddressToString} Catch [exception] { $_ } }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment