|
|
Line 1: |
Line 1: |
| <#
| |
|
| |
| .SYNOPSIS
| |
| Skript hostide portide avatust vastavalt etteantud hostide ja portide mimekijale
| |
|
| |
| .DESCRIPTION
| |
| Skript kontrollib hosti portide avatust vastavalt parameetritena etteantud nimekrijadele.
| |
| Juhul kui hostide või portide nimekija pole ettantud siis skript lõpetab töö.
| |
| Kontrollitavale ip aadressile tehakse nimelahendus ja avatud ja suletud pordid kuvatakse erivärviliselt.
| |
| Avatud pordid on tulemuses rohelist värvi ja suletud punast värvi.
| |
|
| |
|
| .EXAMPLE
| |
| ./testports.ps1 hostlist.txt portlist.txt
| |
|
| |
| .VERSION
| |
| 0.2
| |
|
| |
| .NOTES
| |
| Autor: Andres Kõrvemaa
| |
|
| |
| #>
| |
|
| |
|
| |
| # Deklareerime parameetrid
| |
| param([string]$hostid,[string]$pordid)
| |
| # Kontrollime Hostide nimekirja olemasolu
| |
| if ($hostid -eq ""){
| |
| Write-Host "Hostide nimekirja pole määratud! " -ForegroundColor Yellow
| |
| break
| |
| }
| |
| # Kontrollime portide nimekirja olemasolu
| |
| If ($pordid -eq ""){
| |
| Write-Host "Portide nimekirja parameetrit pole määratud !!" -ForegroundColor Yellow
| |
| break
| |
| }
| |
| # Loeme failist sisse hostid
| |
| [Array]$hostlist = Get-Content $hostid
| |
| # Loeme failist sisse pordid
| |
| [Array]$ports = Get-Content $pordid
| |
|
| |
| $ping = new-object System.Net.NetworkInformation.Ping
| |
|
| |
|
| |
| foreach ($ip in $hostlist) {
| |
| $tulemus = $ping.send($ip)
| |
| $dnsnimi = ([System.Net.Dns]::GetHostByAddress("$ip")).HostName
| |
|
| |
| if (! $?){
| |
| Write-Host "Host:" $dnsnimi $ip "- not found" -ForegroundColor Red
| |
| }
| |
|
| |
|
| |
| else {
| |
| if ($tulemus.status.tostring() –eq “Success”) {
| |
|
| |
| write-host $dnsnimi $ip "- Ports: " -foregroundColor Yellow -NoNewline
| |
| foreach ($port in $ports){
| |
| $socket = new-object System.Net.Sockets.TcpClient($ip, $port)
| |
| if ($socket –eq $null) {
| |
| write-host "$port," -ForegroundColor Red -NoNewline
| |
| }
| |
| else {
| |
| write-host "$port,"-foregroundcolor Green -NoNewline
| |
| $socket = $null
| |
| }
| |
| }
| |
| }
| |
| else {
| |
| write-host "Host: $ip - down" -ForegroundColor Red
| |
| }
| |
| }
| |
| Write-Host ""
| |
| }
| |
| $ping = $null
| |