diff --git a/PS_Script.ps1 b/PS_Script.ps1 index 6497647..57154b7 100644 --- a/PS_Script.ps1 +++ b/PS_Script.ps1 @@ -9,26 +9,33 @@ Write-Host "IP of your Ethernet port" -Separator " -> " -ForegroundColor Yello Write-Host "Start scanning IP addresses in your local network ..." -ForegroundColor White "`n" # New line -$InputFile = 'List_config.txt' # Associated file to a variable +$InputFile = '.\List_config.txt' # Associated file to a variable $String = Get-content $InputFile # Read file as a string # $count = 0 # $totIP = (Get-Content $InputFile).Length # Total number of IP listed in file + foreach ($IPn in $String) # For each IP listed in file { # Percentage = (counter/total)*100 with truncation - #$Percent = [math]::floor(($count/$totIP) * 100) + # $Percent = [math]::floor(($count/$totIP) * 100) # Display progress - #Write-Progress -Activity "Search in Progress" -Status "$Percent% complete" #-PercentComplete $Percent - #$count = $count+1 + # Write-Progress -Activity "Search in Progress" -Status "$Percent% complete" #-PercentComplete $Percent + # $count = $count+1 - if (Test-Connection $IPn -Quiet -Count 1 -ErrorAction SilentlyContinue) # Check if IP is reachable + if ($IPn.contains(“#”)) # skip if IP is commented with # character at the beginning { - Write-Host ("$IPn","CONNECTED") -Separator " - " -ForegroundColor Green + } - else # IP is not reachable - { - Write-Host ("$IPn","NOT CONNECTED") -Separator " - " -ForegroundColor Red + else{ + if (Test-Connection $IPn -Quiet -Count 1 -ErrorAction SilentlyContinue) # Check if IP is reachable + { + Write-Host ("$IPn","CONNECTED") -Separator " - " -ForegroundColor Green + } + else # IP is not reachable + { + Write-Host ("$IPn","NOT CONNECTED") -Separator " - " -ForegroundColor Red + } } } @@ -37,7 +44,7 @@ Write-Host "Done." -ForegroundColor White Write-Host "To edit IP addresses list, open file List_config.txt." -ForegroundColor White # After 60 seconds, close the window. - Start-Sleep -s 60 +Start-Sleep -s 60 # Waiting for user input to close the window. # Read-Host -Prompt "Press Enter to exit " \ No newline at end of file