Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test-PSOnePing: System.Net.Networkinformation.Ping details #1

Open
scriptingstudio opened this issue Nov 21, 2019 · 1 comment
Open

Comments

@scriptingstudio
Copy link

Method .send() takes time to resolve hostname if you pass not ipaddress. So if you pass a dead name you will get an exception.
I would suggest this solution:

if (-not [bool]($ComputerName -as [ipaddress])) {
	try {
		$result = [System.Net.Dns]::BeginGetHostByName($ComputerName, $null, $null)
		$result = if ($result.AsyncWaitHandle.WaitOne($timeout)) { [System.Net.Dns]::EndGetHostByName($result) }
		if (-not $result) {return $false}
		$ComputerName = $result.AddressList.IPAddressToString
	} catch {return $false}
}
@TobiasPSP
Copy link
Owner

Great suggestion! Will look at it and incorporate the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants