python实现基于SSL的IRC bot实例介绍
June 17, 2015
python基于SSL的IRC bot实例是如何来实现的呢?下面的内容将会通过具体的实例来演示python基于SSL的IRC bot实例的实现方法及相关技巧:
本文实例讲述了python简单实现基于SSL的 IRC bot。分享给大家供大家参考。具体如下:
#!/usr/bin/python # -*- coding: utf8 -*- import socket, string, time, ssl import urllib, re network = 'irc.server.net' nick = 'nickname' chan = 'bot' port = 6697 socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) def main(network, nick, chan, port): socket.connect((network,port)) irc = ssl.wrap_socket(socket) irc.send('NICK %srn' % nick) print irc.recv(4096) irc.send('USER %s %s %s :My botrn' % (nick,nick,nick)) print irc.recv(4096) irc.send('JOIN #%srn' % chan) print irc.recv(4096) while True: data = irc.recv(4096) print data if data.find('PING') != -1: irc.send('PONG '+data.split()[1]+'rn') if data.find('!gtforn') != -1: irc.send('QUITrn') exit() print data if __name__=='__main__': main(network, nick, chan, port)
python基于SSL的IRC bot实例就是这样,欢迎大家参考。。。。
0 Comments