Skip to content

Commit 96ea87b

Browse files
committed
Code improved
1 parent 4592b40 commit 96ea87b

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed
10.5 KB
Loading
File renamed without changes.
-12 KB
Binary file not shown.

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ This powerful asynchronus IPv4 Port Scanner allows you to scan every Port-Range
88

99
The result will contain the Port number, Protocol, Service name, Description and the Status.
1010

11-
![Screenshot](Documentation/Images/New-IPv4PortScan.png?raw=true "New-IPv4PortScan")
11+
![Screenshot](Documentation/Images/IPv4PortScan.png?raw=true "New-IPv4PortScan")
1212

1313
To reach the best possible performance, this script uses a [RunspacePool](https://msdn.microsoft.com/en-US/library/system.management.automation.runspaces.runspacepool(v=vs.85).aspx). As you can see in the following screenshot, the individual tasks are distributed across all cpu cores:
1414

15-
![Screenshot](Documentation/Images/New-IPv4PortScan_CPUusage.png?raw=true "CPU usage")
15+
![Screenshot](Documentation/Images/IPv4PortScan_CPUusage.png?raw=true "CPU usage")
1616

1717
If you are looking for a module containing this script... you can find it [here](https://github.com/BornToBeRoot/PowerShell)!
1818

@@ -21,17 +21,16 @@ Maybe you're also interested in my asynchronus [IPv4 Network Scanner](https://gi
2121
## Syntax
2222

2323
```powershell
24-
.\New-IPv4PortScan.ps1 [-ComputerName] <String> [[-StartPort] <Int32>] [[-EndPort] <Int32>] [[-Threads] <Int32>] [[-Force]] [[-UpdateList]] [<CommonParameters>]
24+
.\IPv4PortScan.ps1 [-ComputerName] <String> [[-StartPort] <Int32>] [[-EndPort] <Int32>] [[-Threads] <Int32>] [[-Force]] [[-UpdateList]] [<CommonParameters>]
2525
```
2626

2727
## Example
2828

2929
```powershell
30-
PS> .\New-IPv4PortScan.ps1 -ComputerName fritz.box -EndPort 500
30+
PS> .\IPv4PortScan.ps1 -ComputerName fritz.box -EndPort 500
3131
3232
Port Protocol ServiceName ServiceDescription Status
3333
---- -------- ----------- ------------------ ------
34-
21 tcp ftp File Transfer Protocol [Control] open
3534
53 tcp domain Domain Name Server open
3635
80 tcp http World Wide Web HTTP open
3736
```
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
###############################################################################################################
22
# Language : PowerShell 4.0
3-
# Filename : New-IPv4PortScan.ps1
3+
# Filename : IPv4PortScan.ps1
44
# Autor : BornToBeRoot (https://github.com/BornToBeRoot)
55
# Description : Powerful asynchronus IPv4 Port Scanner
66
# Repository : https://github.com/BornToBeRoot/PowerShell_IPv4PortScanner
@@ -16,11 +16,10 @@
1616
The result will contain the Port number, Protocol, Service name, Description and the Status.
1717
1818
.EXAMPLE
19-
.\New-IPv4PortScan.ps1 -ComputerName fritz.box -EndPort 500
19+
.\IPv4PortScan.ps1 -ComputerName fritz.box -EndPort 500
2020
2121
Port Protocol ServiceName ServiceDescription Status
2222
---- -------- ----------- ------------------ ------
23-
21 tcp ftp File Transfer Protocol [Control] open
2423
53 tcp domain Domain Name Server open
2524
80 tcp http World Wide Web HTTP open
2625
@@ -268,10 +267,13 @@ Process{
268267
$Status = "Closed"
269268
}
270269

271-
[pscustomobject] @{
272-
Port = $Port
273-
Protocol = "tcp"
274-
Status = $Status
270+
if($Status -eq "Open")
271+
{
272+
[pscustomobject] @{
273+
Port = $Port
274+
Protocol = "tcp"
275+
Status = $Status
276+
}
275277
}
276278
}
277279

@@ -327,7 +329,7 @@ Process{
327329
$Jobs_ToProcess = $Jobs | Where-Object {$_.Result.IsCompleted}
328330

329331
# If no jobs finished yet, wait 500 ms and try again
330-
if($Jobs_ToProcess -eq $null)
332+
if($null -eq $Jobs_ToProcess)
331333
{
332334
Write-Verbose -Message "No jobs completed, wait 500ms..."
333335

@@ -348,7 +350,7 @@ Process{
348350

349351
Write-Progress -Activity "Waiting for jobs to complete... ($($Threads - $($RunspacePool.GetAvailableRunspaces())) of $Threads threads running)" -Id 1 -PercentComplete $Progress_Percent -Status "$Jobs_Remaining remaining..."
350352

351-
Write-Verbose -Message "Processing $(if($Jobs_ToProcess.Count -eq $null){"1"}else{$Jobs_ToProcess.Count}) job(s)..."
353+
Write-Verbose -Message "Processing $(if($null -eq $Jobs_ToProcess.Count){"1"}else{$Jobs_ToProcess.Count}) job(s)..."
352354

353355
# Processing completed jobs
354356
foreach($Job in $Jobs_ToProcess)
@@ -361,7 +363,7 @@ Process{
361363
$Jobs.Remove($Job)
362364

363365
# Check if result is null --> if not, return it
364-
if($Job_Result -ne $null -and $Job_Result.Status -eq "Open")
366+
if($Job_Result.Status)
365367
{
366368
if($AssignServiceWithPort)
367369
{

0 commit comments

Comments
 (0)