Skip to content
This repository was archived by the owner on Jul 8, 2023. It is now read-only.

Commit 374d41a

Browse files
committed
update: readme
1 parent 0362245 commit 374d41a

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

README.md

+29-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,29 @@
1-
# port-scanner
2-
Fast API for scanning ports of a host.
1+
<h1 align="center">
2+
Port Scanner
3+
</h1>
4+
5+
<p align="center">
6+
Fast library for scanning ports of a host
7+
</p>
8+
9+
## How to use?
10+
You need to give a host address and port range, after that the scanner will
11+
check the ports and returns the open ports.
12+
```go
13+
package main
14+
15+
import (
16+
"fmt"
17+
18+
scanner "github.com/amirhnajafiz/port-scanner"
19+
)
20+
21+
func main() {
22+
// creating scanner with URI, Port Range, Number of workers (optional, default is 100)
23+
openports := scanner.Scan("", 2048)
24+
25+
for _, port := range openports {
26+
fmt.Printf("%d open\n", port)
27+
}
28+
}
29+
```

example/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
func main() {
10-
openports := scanner.Scan("", 2048, 100)
10+
openports := scanner.Scan("", 2048)
1111

1212
for _, port := range openports {
1313
fmt.Printf("%d open\n", port)

scanner.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import (
99
// Scan takes a uri, portRange and number of workers and will
1010
// test the uri ports in portRange (0, portRange) with workers and then
1111
// returns the open ports.
12-
func Scan(uri string, portRange int, numberOfWorkers int) []int {
12+
func Scan(uri string, portRange int, workers ...int) []int {
13+
numberOfWorkers := 100
14+
if len(workers) > 0 {
15+
numberOfWorkers = workers[0]
16+
}
17+
1318
ports := make(chan int, numberOfWorkers)
1419
response := make(chan int)
1520

0 commit comments

Comments
 (0)