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
import socket, base64, ssl

user = "user"
server = "jabber.org"
port = 5222
password = "password"
recipient = "[email protected]"
message = "hello"
useSSL = True

def waitfor(socket, element) :
  input = ""  
  while not ("<" + element) in input or not input.endswith(">") :
    input += s.recv(1024)

s = socket.socket()
s.connect((server, port))
header = "<stream:stream version='1.0' xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' to='" + server + "' xmlns:xml='http://www.w3.org/XML/1998/namespace'>"
if useSSL :
  s.send(header + "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>")
  waitfor(s, "proceed")
  s = ssl.wrap_socket(s)
s.send(header + "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>" + base64.b64encode("\0" + user + "\0" + password)+ "</auth>")
waitfor(s, "success")
s.send(header + "<iq type='set'><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/></iq><iq type='set'><session xmlns='urn:ietf:params:xml:ns:xmpp-session'/></iq><message to='" + recipient + "'><body>" + message + "</body></message>")
s.close()