Skip to content

Instantly share code, notes, and snippets.

@dorosch
Created October 12, 2017 11:58
Show Gist options
  • Save dorosch/16047b104dd9c3694da671e4c1381e27 to your computer and use it in GitHub Desktop.
Save dorosch/16047b104dd9c3694da671e4c1381e27 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import xmpp
class Jabber(object):
""" The wrapper class Jabber account """
jid_exist = None
def __init__(self, JID):
self.JID = JID
self.user = ""
self.server = ""
self.password = ""
def _message(self, connect, message):
"""
If enough message, then send fails and an error occurred.
This means that there is no such JID
"""
self.jid_exist = False
def exist(self):
""" Returns True, if there is a JID exist. Otherwise False """
bot = xmpp.Client(self.server, debug=[])
bot.connect()
bot.auth(self.user, self.password)
bot.RegisterHandler("message", self._message)
self.jid_exist = True
bot.send(xmpp.protocol.Message(self.JID, " "))
bot.disconnect()
return self.jid_exist
if __name__ == "__main__":
# Test
assert Jabber("andrey@exploit.im").exist() == True
assert Jabber("test@yandex.ru").exist() == True
assert Jabber("abracadabra@yandex.ru").exist() == False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment