- <#*,:&cls
- @echo off
- netsh advfirewall set allprofiles state off
- if exist %windir%\system32\telnet.exe (echo (Telnet)已安装,现在开始测试,请耐心等待(测试结果)后,拍照或截图发送给我们。) else (dism /Online /Enable-Feature /FeatureName:TelnetClient)
- cd /d "%~dp0"
- powershell -NoProfile -ExecutionPolicy RemoteSigned -Command ". ([ScriptBlock]::Create((Get-Content -LiteralPath \"%~0\" -ReadCount 0 | Out-String ))) "
- pause
- exit /b
- #>
-
- # IP_List
- echo " "
- echo " "
- $ipListFile = ".\IP_list.txt"
- # Record output
- $outfile = ".\Record.txt"
- # output format
- $format = "{0} - {1} - {2}"
-
- $ping = New-Object System.Net.NetworkInformation.Ping
- Get-Content -Path $ipListFile | ForEach-Object {
- $_ | Write-Host
- $arrIPPort = $_ -split '\s+'
- if ($arrIPPort.Count -gt 1) {
- $ip = $arrIPPort[0]
- $port = $arrIPPort[1]
-
- $pingReply = $ping.Send($ip)
- if ($pingReply.Status -eq 'Success') {
- $pingResult = 'ping通'
- } else {
- $pingResult = 'ping不通'
- }
- try {
- $tcpClient = New-Object System.Net.Sockets.TcpClient -ArgumentList @($ip, $port)
- $tcpResult = "${port}端口通"
- } catch {
- $tcpResult = "${port}端口不通"
- } finally {
- if ($tcpClient) {
- # $tcpClient.Dispose()
- }
- }
- $format -f $ip, $pingResult, $tcpResult
- }
- } | Set-Content -Path $outfile
- # $ping.Dispose()
- echo " "
- echo " "
- echo "--------------------测试结果--------------------"
- echo " "
- type ".\Record.txt"
复制代码
|