python简单实现基于SSL的IRC bot实例
时间:2021-12-08 14:52 作者:admin
本文实例讲述了python/' target='_blank'>python简单实现基于SSL的 IRC bot。分享给大家供大家参考。具体如下:
#!/usr/bin/Python# -*- coding: utf8 -*-import socket, string, time, sslimport urllib, renetwork = 'irc.server.net'nick = 'nickname'chan = 'bot'port = 6697socket = 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 %s\r\n' % nick) print irc.recv(4096) irc.send('USER %s %s %s :My bot\r\n' % (nick,nick,nick)) print irc.recv(4096) irc.send('JOIN #%s\r\n' % chan) print irc.recv(4096) while True: data = irc.recv(4096) print data if data.find('PING') != -1: irc.send('PONG '+data.split()[1]+'\r\n') if data.find('!gtfo\r\n') != -1: irc.send('QUIT\r\n') exit() print dataif __name__=='__main__': main(network, nick, chan, port)
希望本文所述对大家的Python程序设计有所帮助。
(责任编辑:admin)