Advertisement
Nestor10

Get-Hostname

Mar 15th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Get-Hostname { # PTR lookup with timeout (in whole seconds, unfortunately)
  2.     param( [IPAddress]$IPv4, [Int]$Timeout )
  3.  
  4.     # Resolve address within requested timeout period
  5.     if ($Timeout) {
  6.         $hostname = (Start-Job { [System.Net.Dns]::GetHostByAddress($input).HostName } -InputObject $IPv4 | Wait-Job -Timeout $Timeout | Receive-Job);
  7.     # Resolve address the normal way that might take a long time to fail
  8.     } else {
  9.         $hostname = [System.Net.Dns]::GetHostByAddress($IPv4).HostName;
  10.     }
  11.  
  12.     Return $hostname;
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement