Skip to content

Commit

Permalink
added network scanning code
Browse files Browse the repository at this point in the history
  • Loading branch information
waltdigital committed Aug 1, 2022
1 parent 95f2937 commit 932c9e4
Show file tree
Hide file tree
Showing 10 changed files with 252 additions and 9 deletions.
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

7 changes: 6 additions & 1 deletion .idea/eth_go.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

114 changes: 114 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions network_scanner/concurrent_scanning.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"fmt"
"net"
"sync"
)

func main() {
// scanning too quickly
//for i := 1; i <= 1024; i++ {
// go func(j int) {
// address := fmt.Sprintf("192.168.56.101:%d", j)
// conn, err := net.Dial("tcp", address)
// if err != nil {
// return
// }
// err = conn.Close()
// if err != nil {
// log.Fatal(err)
// }
// fmt.Println("%d open\n", j)
// }(i)
//}

host := "scanme.nmap.org"
var wg sync.WaitGroup
for i := 1; i < 1024; i++ {
wg.Add(1)
go func(j int) {
defer wg.Done()
address := fmt.Sprintf("%s:%d", host, j)
conn, err := net.Dial("tcp", address)
if err != nil {
return
}
err = conn.Close()
if err != nil {
fmt.Println("[-] Error closing connection!")
return
}
fmt.Printf("[+] %d open\n", j)
}(i)
}
wg.Wait()
}
31 changes: 31 additions & 0 deletions network_scanner/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
"fmt"
"net"
"sync"
)

func scanPort(port int, wg *sync.WaitGroup) {
defer wg.Done()
IP := "192.168.56.101"
address := fmt.Sprintf(IP+":%d", port)
connection, err := net.Dial("tcp", address)
if err == nil {
fmt.Printf("[+] Connection established... PORT %v\n", port)
} else {
fmt.Printf("[-] No connection established... PORT %v\n", port)
return
}
connection.Close()
}

func main() {
var wg sync.WaitGroup
for i := 1; i < 100; i++ {
wg.Add(1)
go scanPort(i, &wg)
}
wg.Wait()
fmt.Println("[+] Execution completed.")
}
5 changes: 5 additions & 0 deletions network_scanner/nmap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package main

func main() {

}
32 changes: 32 additions & 0 deletions network_scanner/nonconcurrent_scanning.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"fmt"
"log"
"net"
)

func main() {
// testing for loop
//for i := 1; i <= 1024; i++ {
// address := fmt.Sprintf("scanme.nmap.org:%d", i)
// fmt.Println(address)
//}

for i := 1; i <= 1024; i++ {
host := "192.168.56.101"
address := fmt.Sprintf("%s:%d", host, i)
// fmt.Printf("Scanning host: %s\n", address)
conn, err := net.Dial("tcp", address)
if err != nil {
// port is closed or filtered if err != nil
continue
}
err = conn.Close()
if err != nil {
log.Fatal(err)
}
fmt.Printf("PORT %d: open\n", i)
}

}
2 changes: 2 additions & 0 deletions network_scanner/notes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# bypassing firewalls with port forwarding

14 changes: 14 additions & 0 deletions network_scanner/scanner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import (
"fmt"
"net"
)

// main contains a basic port scanner
func main() {
_, err := net.Dial("tcp", "scanme.nmap.org:80")
if err == nil {
fmt.Println("[+] Connection successful.")
}
}
2 changes: 2 additions & 0 deletions network_scanner/time
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[+] 22 open
[+] 80 open

0 comments on commit 932c9e4

Please sign in to comment.