-
Notifications
You must be signed in to change notification settings - Fork 0
/
xpy.go
69 lines (62 loc) · 2.48 KB
/
xpy.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
package main
import (
"crypto/tls"
"fmt"
"log"
"time"
"github.com/xmppo/go-xmpp"
)
func main() {
// Define your credentials and recipient details
username := "your_username@thesecure.biz"
password := "your_password"
recipient := "recipient@thesecure.biz"
message := "Hello from Go xpy!"
// Set up XMPP options with TLS enabled
options := xmpp.Options{
Host: "xmpp_server.com:5222", // XMPP server and port
User: username,
Password: password,
NoTLS: false, // Require TLS for secure connection
StartTLS: true, // Enable STARTTLS if supported by the server
TLSConfig: &tls.Config{InsecureSkipVerify: true}, // Adjust for local server testing; set to false in production
Debug: true, // Enable debugging output (Actually it's not necessary)
Session: true,
Status: "chat",
StatusMessage: "xpy Hello !",
}
// Create an XMPP client
client, err := options.NewClient()
if err != nil {
log.Fatalf("Failed to create XMPP client: %v", err)
}
// Send a message to the recipient
_, err = client.Send(xmpp.Chat{
Remote: recipient,
Type: "chat",
Text: message,
})
if err != nil {
log.Fatalf("Failed to send message: %v", err)
}
fmt.Printf("Message sent to %s: %s\n", recipient, message)
// Listen for incoming messages
go func() {
for {
chat, err := client.Recv()
if err != nil {
log.Printf("Failed to receive message: %v", err)
break
}
switch v := chat.(type) {
case xmpp.Chat:
fmt.Printf("Received message from %s: %s\n", v.Remote, v.Text)
case xmpp.Presence:
fmt.Printf("Presence from %s: %s\n", v.From, v.Show)
}
}
}()
// API key: <2_@l?/9VoiZB56&6NPHPX#mK_gS$p&(EU'@egTc:ym/X)#/E_<yb
// Keep the program running to receive messages
time.Sleep(10 * time.Second)
}