Skip to content

Instantly share code, notes, and snippets.

@sinky
Forked from mbrownnycnyc/veryfastping.ps1
Created September 2, 2016 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sinky/54b64c873c02d61cf444977471e6c72c to your computer and use it in GitHub Desktop.
Save sinky/54b64c873c02d61cf444977471e6c72c to your computer and use it in GitHub Desktop.
test-connection got you down? ping just not cutting it for you? How about using the System.Net.NetworkInformation.Ping.send() method
# with reference to http://theadminguy.com/2009/04/30/portscan-with-powershell/
function fastping{
[CmdletBinding()]
param(
[String]$computername = "127.0.0.1",
[int]$delay = 100
)
$ping = new-object System.Net.NetworkInformation.Ping
# see http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ipstatus%28v=vs.110%29.aspx
try {
if ($ping.send($computername,$delay).status -ne "Success") {
return $false;
}
else {
return $true;
}
} catch {
return $false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment