萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> 編程語言綜合 >> python簡單實現基於SSL的IRC bot實例

python簡單實現基於SSL的IRC bot實例

         本文實例講述了python簡單實現基於SSL的 IRC bot。分享給大家供大家參考。具體如下:

? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 #!/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程序設計有所幫助。

copyright © 萬盛學電腦網 all rights reserved