-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (48 loc) · 1.4 KB
/
main.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"log"
"net"
"os"
"strconv"
"strings"
"tcp/rapaping"
"github.com/gookit/color"
)
const (
infoFormat = ` Address Details:
│ Address: [ %s ]
│ Hostname: [ %s ]
│ City: [ %s ]
│ Region: [ %s ]
│ Country: [ %s ]
│ ASN/ISP: [ %s ]
`
)
var logger = log.New(os.Stdout, "", 0)
func main() {
if len(os.Args) != 3 {
color.Error.Printf("Usage: go run main.go ip port")
}
host := os.Args[1]
port, err := strconv.Atoi(os.Args[2])
if err != nil || !rapaping.IsValidPort(port) {
color.Error.Printf("Invalid port number:", err)
}
logger.Println("rapaping v1.4.88 - Copyright (c) 1917 Big Armenian Daddy")
logger.Printf("\nConnecting to "+color.Green.Sprint("%s")+" on "+color.Green.Sprint("TCP %d")+":\n\n", host, port)
ips, err := net.LookupIP(host)
if err != nil {
color.Error.Printf("Failed to resolve %s: %v", host, err)
os.Exit(1)
} else if ips[0].String() != "::1" && ips[0].String() != "127.0.0.1" {
ipInfo, err := rapaping.GetIPInfo(ips[0].String())
if err == nil {
logger.Printf(infoFormat, color.Green.Sprint(strings.Join(rapaping.TransformIPArray(ips), ", ")), color.Green.Sprint(ipInfo.Hostname), color.Green.Sprint(ipInfo.City), color.Green.Sprint(ipInfo.Region), color.Green.Sprint(ipInfo.Country), color.Green.Sprint(ipInfo.Org))
}
}
info := &rapaping.Info{
Host: host,
Port: port,
}
rapaping.Run(info)
}