Created
July 4, 2012 07:36
-
-
Save everplays/3045930 to your computer and use it in GitHub Desktop.
a simple script to ping another jid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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