-
Notifications
You must be signed in to change notification settings - Fork 0
/
httpTest.go
54 lines (45 loc) · 1.2 KB
/
httpTest.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
package main
import (
"crypto/tls"
"flag"
"fmt"
"os"
"strings"
"gopkg.in/ldap.v3"
)
func main() {
// Command-line flags
uri := flag.String("Uri", "", "The URI to test (e.g., ldaps://example.com:636)")
flag.Parse()
// Check if URI is provided
if *uri == "" {
fmt.Println("Please provide a URI using the -Uri flag.")
os.Exit(1)
}
// Parse URI to get host and port
parts := strings.Split(*uri, "://")
if len(parts) != 2 {
fmt.Println("Invalid URI format. Please use a valid URI (e.g., ldaps://example.com:636).")
os.Exit(1)
}
host := parts[1]
if !strings.Contains(host, ":") {
fmt.Println("Please specify a port in the URI (e.g., ldaps://example.com:636).")
os.Exit(1)
}
// Disable security checks for simplicity. In a production environment, you should handle this more securely.
ldap.DefaultTimeout = 10 // seconds
l, err := ldap.DialTLS("tcp", host, &tls.Config{InsecureSkipVerify: true})
if err != nil {
fmt.Printf("Error: %v\n", err)
os.Exit(1)
}
defer l.Close()
// Make a simple bind to check if the connection is successful
err = l.Bind("", "")
if err != nil {
fmt.Printf("Error: Unable to bind. %v\n", err)
os.Exit(1)
}
fmt.Printf("Success! Connected to %s\n", *uri)
}