0
我需要幫助寫一個簡單的shell腳本,它會掃描協議的端口:FTP ,SSH,SMTP,HTTP爲網絡中的前10臺主機。寫一個簡單的shell腳本,它會掃描協議的端口:FTP,SSH,SMTP,HTTP的第10個網絡中的主機
#Select port range
$portrange = 20,21,22,25,80
#Open connection for each port from the range
Foreach ($p in $portrange)
{
$Socket = New-Object Net.Sockets.TcpClient
$ErrorActionPreference = 'SilentlyContinue'
#Connect on the given port
$Socket.Connect("10.59.80.64/24")
#Determine if the connection is established
if ($Socket.Connected) {
Write-Host "Outbound port $p is open." -ForegroundColor Yellow
$Socket.Close()
}
else {
Write-Host "Outbound port $p is closed or filtered."}
} #end foreach
感謝
嗨路易斯,這是我的代碼,但我試圖增加更多的主機, #選擇端口範圍 $ portrange = 20,21,22,25,80 #Open連接從每個端口範圍 FOREACH(在$ $ portrange p) { $插座=新物體Net.Sockets.TcpClient $ ErrorActionPreference = 'SilentlyContinue' #Connect給定端口 $ Socket.Connect(「10.59.80.64/上24" ) #Determine如果連接是如果($ Socket.Connected){ 的Wri建立 te-Host「出站端口$ p已打開。」 -ForegroundColor黃 $ Socket.Close() } 其他{ 寫主機「出站口$ p被關閉或過濾。」}} 的foreach#結束 – John
哦對不起我以爲你使用shell Linux,但我看到它的電源外殼。在這種情況下,我會回答。 –