2012/06/25


今天在找利用python 來傳gtalk訊息的方法
並不困難
程式碼如下

import xmpp

login = 'abcde' # @gmail.com
pwd   = '123456'

cnx = xmpp.Client('gmail.com')
cnx.connect( server=('talk.google.com',5222) )

cnx.auth(login,pwd, 'botty')

cnx.send( xmpp.Message( "defghi@gmail.com" ,"Hello World from abcde!!!" ) )

==========================================================

加上測port變成一個監控机器人


import xmpp
import socket

address='1.1.1.1'
port = int(80)
p = str(port)
mes=address+' port '+p+' ok'

s = socket.socket()
try:
        s.connect((address,port))
        print s

        login = 'abcde' # @gmail.com
        pwd   = '123456'

        cnx = xmpp.Client('gmail.com')
        cnx.connect( server=('talk.google.com',5222) )

        cnx.auth(login,pwd, 'botty')

        cnx.send( xmpp.Message( "defghi@gmail.com" ,mes ) )
except:
        print "fail"



沒有留言: