brewersfan1976

irc-read-new.rb

Feb 28th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.32 KB | None | 0 0
  1. # IRC Read program
  2. # Written by Bryan Miller
  3.  
  4. # get sockets from standard library
  5.  
  6. require 'socket'
  7.  
  8. # get SSL sockets from standard library
  9.  
  10. require 'openssl'
  11.  
  12. # get hostname to connect to from the user
  13.  
  14. print "hostname: "
  15. hostname = gets.chomp
  16.  
  17. # for SSL port is always 6697
  18.  
  19. port = 6697
  20.  
  21. # open the socket by connecting to the hostname and port
  22.  
  23. s = TCPSocket.open(hostname, port)
  24. ssl_context = OpenSSL::SSL::SSLContext.new()
  25. ssl_context.ssl_version = :SSLv23
  26. ssl_socket = OpenSSL::SSL::SSLSocket.new(s, ssl_context)
  27. ssl_socket.sync_close = true
  28. ssl_socket.connect
  29.  
  30. # send nickname to the server
  31.  
  32. ssl_socket.puts "NICK linux1976\r\n"
  33.  
  34. # send user info to the server
  35.  
  36. ssl_socket.puts "USER linux1976 8 * :linux\r\n"
  37.  
  38. # send registration info to the server to identify your registered nick
  39.  
  40. ssl_socket.puts "NICKSERV identify (enter your password here)\r\n"
  41.  
  42. # get channel to join from the user and join the channel
  43.  
  44. print "Enter channel to join: "
  45. channel = gets.chomp
  46. ssl_socket.puts "JOIN #" + channel
  47.  
  48. # read data from chatroom and print it to the screen
  49.  
  50. while line = ssl_socket.gets
  51.       puts line.chop
  52.  
  53.       if line.include? "PING :" then
  54.          ssl_socket.puts "PONG :Linux Rocks !!"
  55.          puts "PONG :Linux Rocks !!"
  56.       end
  57. end
  58.  
  59. # close socket when done
  60.  
  61. ssl_socket.close
Advertisement
Add Comment
Please, Sign In to add comment