-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
40 lines (36 loc) · 751 Bytes
/
main.go
File metadata and controls
40 lines (36 loc) · 751 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"fmt"
"net"
"strconv"
"time"
)
func ip_input() string {
var ip string
fmt.Print("Enter an IP address: ")
fmt.Scanln(&ip)
return ip
}
//ping a host port from 1 to 3306 if no response after 2 seconds close connection and continue to next port and print the response
func scan_tcp(ip string) {
for i := 22; i < 3306; i++ {
conn, err := net.Dial("tcp", ip+":"+strconv.Itoa(i))
if err != nil {
continue
}
conn.SetDeadline(time.Now().Add(2 * time.Second))
defer conn.Close()
fmt.Println("Port", i, "is open")
response := make([]byte, 1024)
_, err = conn.Read(response)
if err != nil {
continue
}
fmt.Println(string(response))
conn.Close()
}
}
func main() {
ip := ip_input()
scan_tcp(ip)
}