python简单实现基于SSL的IRC bot实例
本文实例讲述了python简单实现基于SSL的IRCbot。分享给大家供大家参考。具体如下:
#!/usr/bin/python #-*-coding:utf8-*- importsocket,string,time,ssl importurllib,re network='irc.server.net' nick='nickname' chan='bot' port=6697 socket=socket.socket(socket.AF_INET,socket.SOCK_STREAM) defmain(network,nick,chan,port): socket.connect((network,port)) irc=ssl.wrap_socket(socket) irc.send('NICK%s\r\n'%nick) printirc.recv(4096) irc.send('USER%s%s%s:Mybot\r\n'%(nick,nick,nick)) printirc.recv(4096) irc.send('JOIN#%s\r\n'%chan) printirc.recv(4096) whileTrue: data=irc.recv(4096) printdata ifdata.find('PING')!=-1: irc.send('PONG'+data.split()[1]+'\r\n') ifdata.find('!gtfo\r\n')!=-1: irc.send('QUIT\r\n') exit() printdata if__name__=='__main__': main(network,nick,chan,port)
希望本文所述对大家的Python程序设计有所帮助。