-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathgetipintel.go
74 lines (62 loc) · 1.84 KB
/
getipintel.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"fmt"
"io/ioutil"
"net/http"
"strconv"
"time"
"os"
)
const (
getIPIntelURL = "http://check.getipintel.net/check.php?" //change URL here if you want to add more arguments
timeout = 5 * time.Second // 5 seconds
maxProbability = 0.99
contactEmail = "yourContactEmail" //Replace with your contact email
)
func checkIP(ip string) (bool, error) {
client := &http.Client{Timeout: timeout}
// Construct the request URL
url := fmt.Sprintf("%sip=%s&contact=%s", getIPIntelURL, ip, contactEmail)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return false, fmt.Errorf("error creating request: %w", err)
}
// Send the request and handle potential errors
resp, err := client.Do(req)
if err != nil {
return false, fmt.Errorf("error sending request: %w", err)
}
defer resp.Body.Close()
// Read the response body and convert to float
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return false, fmt.Errorf("error reading response body: %w", err)
}
probability, err := strconv.ParseFloat(string(body), 64) // Use ParseFloat for precision
if err != nil {
return false, fmt.Errorf("error parsing probability: %w", err)
}
if resp.StatusCode != http.StatusOK {
return false, fmt.Errorf("GetIPIntel API returned error: %s, GetIPIntel error code: %.0f", resp.Status, probability)
}
return probability > maxProbability, nil
}
func main() {
// Get the IP address from command-line arguments or user input
if len(os.Args) != 2 {
fmt.Println("Usage: go run main.go <IP address>")
return
}
ip := os.Args[1]
// Check the IP and handle errors
isSuspicious, err := checkIP(ip)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
if isSuspicious {
fmt.Printf("%s is probably a proxy / VPN / bad IP.\n", ip)
} else {
fmt.Printf("%s is probably NOT a proxy / VPN / bad IP.\n", ip)
}
}