-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/run scan with progress sync function (#60)
Co-authored-by: Elias Flötzinger <[email protected]>
- Loading branch information
Showing
5 changed files
with
227 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/Ullaakut/nmap/v2" | ||
) | ||
|
||
func main() { | ||
scanner, err := nmap.NewScanner( | ||
nmap.WithTargets("localhost"), | ||
nmap.WithPorts("1-4000"), | ||
nmap.WithServiceInfo(), | ||
nmap.WithVerbosity(3), | ||
) | ||
if err != nil { | ||
log.Fatalf("unable to create nmap scanner: %v", err) | ||
} | ||
|
||
progress := make(chan float32, 1) | ||
|
||
// Function to listen and print the progress | ||
go func() { | ||
for p := range progress { | ||
fmt.Printf("Progress: %v %%\n", p) | ||
} | ||
}() | ||
|
||
result, _, err := scanner.RunWithProgress(progress) | ||
if err != nil { | ||
log.Fatalf("unable to run nmap scan: %v", err) | ||
} | ||
|
||
fmt.Printf("Nmap done: %d hosts up scanned in %.2f seconds\n", len(result.Hosts), result.Stats.Finished.Elapsed) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
input=$1 | ||
while IFS= read -r line | ||
do | ||
echo "$line" | ||
sleep .5 | ||
done < "$input" |