Last active
July 17, 2019 05:25
-
-
Save jmurphyau/fdf6f97011c60fbe63752db3c86c12d4 to your computer and use it in GitHub Desktop.
One line powershell to check open ports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
powershell -noprofile -command "& { function conn([string]$h,[int]$p) {$c=New-Object System.Net.Sockets.TcpClient; try {$c.connect($h, $p);return [byte]($c.Connected);}catch{return 0}} function hostport([string]$s){$r=($s -match \"^((?:\d{1,3}\.){3}\d{1,3}):(\d{1,6})$\");$m=$matches;return ($r,$m[1],$m[2])} function chk([string]$dest) { $hp=hostport $dest; if ($hp[0]) { write-host (\"Connection to {0}:{1} = {2}\" -f ($hp[1],$hp[2],@(\"Failed\",\"Success\")[(conn $hp[1] $hp[2])])) } else { write-host (\"Invalid: {0}\" -f $dest) } } foreach ($a in $args) {chk $a} }" 127.0.0.1:22 127.0.0.1:80 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment