Posted By

zhyar on 10/01/12


Tagged

python bot irc ssl


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

icecreamboyy


Simple IRC bot with SSL


 / Published in: Python
 

This is a simple IRC bot connecting with SSL.

  1. #!/usr/bin/python
  2. # -*- coding: utf8 -*-
  3.  
  4. import socket, string, time, ssl
  5. import urllib, re
  6.  
  7. network = 'irc.server.net'
  8. nick = 'nickname'
  9. chan = 'bot'
  10. port = 6697
  11.  
  12. socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
  13.  
  14. def main(network, nick, chan, port):
  15. socket.connect((network,port))
  16. irc = ssl.wrap_socket(socket)
  17. irc.send('NICK %s\r\n' % nick)
  18. print irc.recv(4096)
  19. irc.send('USER %s %s %s :My bot\r\n' % (nick,nick,nick))
  20. print irc.recv(4096)
  21. irc.send('JOIN #%s\r\n' % chan)
  22. print irc.recv(4096)
  23.  
  24. while True:
  25. data = irc.recv(4096)
  26. print data
  27.  
  28. if data.find('PING') != -1:
  29. irc.send('PONG '+data.split()[1]+'\r\n')
  30. if data.find('!gtfo\r\n') != -1:
  31. irc.send('QUIT\r\n')
  32. exit()
  33. print data
  34.  
  35. if __name__=='__main__':
  36. main(network, nick, chan, port)

Report this snippet  

You need to login to post a comment.