Scripts Power Shell :Loop For Check Open Port
###-----------------------------------------------------------###
###--------Author : Mr.Yingkamol Prukrattanakul----###
###---MCP, MCSA, MCSE, MCT, MCST, SEC+----###
###------Email<yingkamol_7@hotmail.com>--------###
###----------------------------------------------------------###
###/////////////////////////////..........\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\###
###///////////////////////////////......\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\###
{
# Define every server IP you need to test:
$servers = Get-Content D:\IPlist.csv
# Define the port number you need to test (eg: 3389 for RDP):
$portToCheck = '3389'
$ErrorActionPreference = 'Stop'
foreach ($server in $servers)
{
If ( Test-Connection $server -Count 1 -Quiet)
{
try
{
$null = New-Object System.Net.Sockets.TCPClient -ArgumentList $server,$portToCheck
$props = @{
Server = $server
PortOpen = 'Yes'
}
}
catch
{
$props = @{
Server = $server
PortOpen = 'No'
}
}
}
Else
{
$props = @{
Server = $server
PortOpen = 'Server did not respond to ping'
}
}
New-Object PsObject -Property $props
}
}
CheckPort > "$env:USERPROFILE\Desktop\CheckPort.csv"
ไม่มีความคิดเห็น:
แสดงความคิดเห็น