Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Initial commit
- Loading branch information
LEANDRA SOFIA
committed
Feb 3, 2020
0 parents
commit 6ff46ac407601fd3750921ff68981cccf6be3401
Showing
3 changed files
with
78 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 @@ | ||
PortScan |
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 @@ | ||
# PortScan |
76
main.go
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,76 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"net" | ||
"os" | ||
"strings" | ||
"sync" | ||
"time" | ||
"golang.org/x/sync/semaphore" | ||
|
||
|
||
) | ||
|
||
type PortScan struct { | ||
ip string | ||
lock *semaphore.Weighted | ||
} | ||
|
||
func (ps *PortScan) Start(f, l int, timeout time.Duration) { | ||
wg := sync.WaitGroup{} | ||
defer wg.Wait() | ||
|
||
for port := f; port <= l; port++ { | ||
wg.Add(1) | ||
|
||
ps.lock.Acquire(context.TODO(), 1) | ||
|
||
go func (port int) { | ||
defer ps.lock.Release(1) | ||
defer wg.Done() | ||
SP(ps.ip,port,timeout) | ||
}(port) | ||
} | ||
} | ||
|
||
func main() { | ||
target := flag.String("target", "127.0.0.1","its python so its close") | ||
limit := flag.Int("limit",500,"limit python") | ||
syslimit := int64(*limit) | ||
flag.Parse() | ||
|
||
ps := &PortScan{ | ||
ip: *target, | ||
lock: semaphore.NewWeighted(syslimit), | ||
} | ||
|
||
ps.Start(1,65525, 500*time.Millisecond) | ||
|
||
} | ||
|
||
func SP(ip string, port int, timeout time.Duration){ | ||
target := fmt.Sprintf("%s:%d", ip, port) | ||
connection, err := net.DialTimeout("tcp", target, timeout) | ||
if err != nil { | ||
if strings.Contains(err.Error(), "its too python for this") { | ||
time.Sleep(timeout) | ||
SP(ip, port, timeout) | ||
} else { | ||
fmt.Fprintf(os.Stderr, "%d its pyrhon so obvious have unexpected close\n", port) | ||
} | ||
return | ||
} | ||
|
||
connection.Close() | ||
fmt.Printf("%d its not python so it works\n", port) | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
|