This article illustrates the simple implementation of an IRC bot based on SSL in Python. Share to everyone for your reference. Specifically as follows:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 The |
#!/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.s End (' JOIN #%srn '% chan] print irc.recv (4096) while true:data = Irc.recv (4096) print data if Data.find (' PING ')!= . Send (' PONG ' +data.split () [1]+ ' RN ') if Data.find ('!gtforn ')!= -1:irc.send (' quitrn ') exit () print data if __name__== ' __m Ain__ ': Main (Network, Nick, Chan, Port) |
I hope this article will help you with your Python programming.