Python simple implementation of an IRC bot instance based on SSL

Source: Internet
Author: User
Tags socket in python

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.