testPorts - Loop through csv and test for open tcp ports using powershell

Simply put, I got tired of using telnet on a bunch of targets while I tested to see if my firewall team got rules in place. Sometimes I am nested deep into a secure network and cannot get to some of the other utilities out there for download.

Setup servers.csv to have each node on a new line and the format of $server, $tcpPort

The code



# Loop through servers.csv and attept to create an tcp connection to each
$csv = Import-Csv servers.csv -Header ("Server","Port")
foreach ($line in $csv) {
  Write-Host "Attempting to connect to " $line.Server " on port " $line.Port
  $tcp = New-Object Net.Sockets.TcpClient
   } catch {}

       $msg = "** Connected! **"
      $msg = "** Failed! **"
    Write-Host $msg


someserver.example.com, 1433
anotherserver.example.com, 1433
Andrew Martin
Lead BI Infrastructure Architect
comments powered by Disqus