Skip to content

Commit

Permalink
v1.2 added check commented IPs on txt file
Browse files Browse the repository at this point in the history
  • Loading branch information
0ern authored Sep 16, 2023
1 parent 8eb86f2 commit d30b39b
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions PS_Script.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand All @@ -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 "

0 comments on commit d30b39b

Please sign in to comment.