Powershell实现Telnet Port

Telnet Port 脚本

 1 $servers = get-content D:\ps\ServerIPAddress.TXT
 2 $portToCheck = '80'
 3 for($i=1;$i -le 120;$i++)
 4 {
 5 foreach ($server in $servers) {
 6  
 7     If ( Test-Connection $server -Count 1 -Quiet) {
 8     
 9         try {       
10             $null = New-Object System.Net.Sockets.TCPClient -ArgumentList $server,$portToCheck
11             $props = @{
12                 Server = $server
13                 PortOpen = 'Yes'
14                 Date=get-date
15             }
16         }
17  
18         catch {
19             $props = @{
20                 Server = $server
21                 PortOpen = 'No'
22                 Date=get-date
23             }
24         }
25     }
26  
27     Else {
28         
29         $props = @{
30             Server = $server
31             PortOpen = 'Server did not respond to ping'
32             Date=get-date
33         }
34     }
35  
36     New-Object PsObject -Property $props | Out-File -Append D:\PS\test-telnet.csv
37 }
38 Start-Sleep -s 10
39 }
View Code

 

posted @ 2017-06-20 15:43  寻香径  阅读(601)  评论(0编辑  收藏  举报