Skip to content

Instantly share code, notes, and snippets.

@everplays
Created July 4, 2012 07:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save everplays/3045930 to your computer and use it in GitHub Desktop.
Save everplays/3045930 to your computer and use it in GitHub Desktop.
a simple script to ping another jid
#!/usr/bin/python
import xmpp
import sys
import random
import optparse
import subprocess
import socket
import re
id = str(random.randint(100, 1000))
def receiver(conn, iq):
if iq.getAttr('id')==id:
print "SUCCESS"
sys.exit(0)
else:
print "FAILURE"
sys.exit(1)
def runtest(options):
jid = xmpp.protocol.JID(options.jid)
# guest agent
client = xmpp.Client(jid.getDomain())
client.connect()
client.auth(jid.getNode(), options.password)
client.RegisterHandler('iq', receiver)
iq = xmpp.simplexml.Node('iq', {"type": "get", "to": options.entity, "id": id})
iq.addChild('ping', namespace="urn:xmpp:ping")
client.send(iq)
while 1:
client.Process(1)
if __name__ == "__main__":
parser = optparse.OptionParser()
parser.add_option("-j", "--jid",
dest="jid",
help="the jid that you want to do the ping from")
parser.add_option("-p", "--password",
dest="password",
help="password of jid")
parser.add_option("-e", "--entity",
dest="entity",
help="jid of entity that you want to ping")
options, args = parser.parse_args()
runtest(options)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment