Python implements SSL-based IRC bot instances and pythonsslircbot

Source: Internet
Author: User

Python implements SSL-based IRC bot instances and pythonsslircbot

This example describes how to implement an SSL-based IRC bot in python. Share it with you for your reference. The details are as follows:

#! /Usr/bin/python #-*-coding: utf8-*-import socket, string, time, sslimport urllib, renetwork = '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 % s \ r \ n' % NICK) print irc. recv (1, 4096) irc. send ('user % s: My bot \ r \ n' % (ni Ck, nick, nick) print irc. recv (1, 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)

I hope this article will help you with 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.