Skip to content

Instantly share code, notes, and snippets.

@kaymccormick
Forked from tskrynnyk/xsend
Created October 29, 2018 13:17
Show Gist options
  • Save kaymccormick/f044a4ece363c32727046585325a4498 to your computer and use it in GitHub Desktop.
Save kaymccormick/f044a4ece363c32727046585325a4498 to your computer and use it in GitHub Desktop.
Command-line utility for sending jabber messages.
#!/usr/bin/python
# xsend: command-line utility for sending jabber messages
# http://xmpppy.sourceforge.net/
#
import sys,os,xmpp,time
if len(sys.argv) < 2:
print "Syntax: xsend JID msg"
sys.exit(0)
tojid = sys.argv[1]
#msg = ' '.join(sys.argv[2:])
data = sys.stdin.readlines()
msg = ' '.join(data)
username = '[email protected]/resource'
password = 'yourpassword'
jid=xmpp.protocol.JID(username)
cl=xmpp.Client(jid.getDomain(),debug=[])
con=cl.connect()
if not con:
sys.exit()
auth=cl.auth(jid.getNode(),password,resource=jid.getResource())
if not auth:
sys.exit()
#cl.SendInitPresence(requestRoster=0) # you may need to uncomment this for old server
id=cl.send(xmpp.protocol.Message(tojid, msg))
time.sleep(1) # some older servers will not send the message if you disconnect immediately after sending
#cl.disconnect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment