-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathralvarez_mqtt.py
More file actions
executable file
·71 lines (56 loc) · 2.05 KB
/
Copy pathralvarez_mqtt.py
File metadata and controls
executable file
·71 lines (56 loc) · 2.05 KB
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
import paho.mqtt.client as mqtt
import time
import socket
# Override DNS resolution in Python
def custom_getaddrinfo(host, port, family=0, socktype=0, proto=0, flags=0):
if host == "stage-app.analytics.t-mobile.com":
print(f"Resolving {host} to 23.50.53.209 (Python override)")
return [(socket.AF_INET, socket.SOCK_STREAM, 6, '', ('23.50.53.209', port))]
else:
# Use normal DNS for other hosts
return orig_getaddrinfo(host, port, family, socktype, proto, flags)
# Backup original function and replace
orig_getaddrinfo = socket.getaddrinfo
socket.getaddrinfo = custom_getaddrinfo
def on_connect(client, userdata, flags, rc):
print(f"Connected to MQTT broker with result code {rc}")
print(f"Connection flags: {flags}")
if rc == 0:
print("SUCCESS! Publishing test message...")
client.publish("test/topic", "Hello from Python MQTT client!")
print("Message sent!")
else:
print(f"Connection failed with code {rc}")
def on_publish(client, userdata, mid):
print(f"Message {mid} published successfully!")
def on_disconnect(client, userdata, rc):
print(f"Disconnected with result code {rc}")
def on_log(client, userdata, level, buf):
print(f"LOG: {buf}")
# Create client with debugging
client = mqtt.Client()
client.on_connect = on_connect
client.on_publish = on_publish
client.on_disconnect = on_disconnect
client.on_log = on_log
# Enable debugging
client.enable_logger()
# Configure for WebSocket
client.ws_set_options(path="/mqtt")
print("Connecting to WebSocket MQTT broker...")
print("Target: stage-app.analytics.t-mobile.com:443/mqtt")
print("Will resolve to: 23.50.53.209")
try:
client.connect("stage-app.analytics.t-mobile.com", 443, keepalive=60)
client.loop_start()
print("Waiting for connection...")
time.sleep(15)
print("Disconnecting...")
client.disconnect()
client.loop_stop()
except Exception as e:
print(f"Error: {e}")
import traceback
traceback.print_exc()
# Restore original function
socket.getaddrinfo = orig_getaddrinfo