编写一个简单的shell脚本,该脚本将扫描网络中前10台主机的端口以查找协议:FTP、SSH、SMTP、HTTP

编写一个简单的shell脚本,该脚本将扫描网络中前10台主机的端口以查找协议:FTP、SSH、SMTP、HTTP,ssh,ftp,smtp,ports,Ssh,Ftp,Smtp,Ports,我需要帮助编写一个简单的shell脚本,该脚本将扫描网络中前10台主机的端口以查找协议:FTP、SSH、SMTP、HTTP #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 $ErrorActionPrefe

我需要帮助编写一个简单的shell脚本,该脚本将扫描网络中前10台主机的端口以查找协议:FTP、SSH、SMTP、HTTP

#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

谢谢

此脚本将扫描端口并将扫描信息保存在scanport.out文件中。 我使用FTP 21、SSH 22、STMP 25和HTTP 80的默认端口

> scanport.out #creates blank file

for i in {0..9} #scan 10 first hosts
do
    nc -v -z 192.168.1.$i 21 >> scanport.out 2>&1 #ftp
    nc -v -z 192.168.1.$i 22 >> scanport.out 2>&1 #ssh
    nc -v -z 192.168.1.$i 25 >> scanport.out 2>&1 #smtp
    nc -v -z 192.168.1.$i 80 >> scanport.out 2>&1 #http
done

我希望它有帮助

此脚本将使用PowerShell扫描端口

$net="10.67.198"
$range=210..220
#Select port range
$portrange = 20,21,22,25,80

foreach ($r in $range) {

    $ip="{0}.{1}" -F $net,$r
    write-host $ip

    #Open connection for each port from the range
    Foreach ($p in $portrange) {

        $Socket = New-Object System.Net.Sockets.TcpClient 

        $ErrorActionPreference = 'SilentlyContinue' 

        #Connect on the given port
        $Socket.Connect($ip, $p)

        $ErrorActionPreference = 'Continue'

        #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."
        }

        $Socket = $null

    }
    #end foreach

}

嗨,luis,这是我的代码,但我正在尝试添加更多主机,从$portrange中的Foreach$p范围中为每个端口选择端口范围$portrange=20,21,22,25,80打开连接{$Socket=New Object Net.Sockets.TcpClient$ErrorActionPreference='SilentlyContinue'连接到给定的端口$Socket.Connect10.59.80.64/24确定如果$Socket.Connected{写主机出站端口$p是打开的。-ForegroundColor黄色$Socket.Close}其他{写入主机出站端口$p已关闭或已筛选。}end foreachOh抱歉,我以为您使用的是shell linux,但我看到它是powershell。在这种情况下,我将回答。