Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # IRC Read program
- # Written by Bryan Miller
- # get sockets from standard library
- require 'socket'
- # get SSL sockets from standard library
- require 'openssl'
- # get hostname to connect to from the user
- print "hostname: "
- hostname = gets.chomp
- # for SSL port is always 6697
- port = 6697
- # open the socket by connecting to the hostname and port
- s = TCPSocket.open(hostname, port)
- ssl_context = OpenSSL::SSL::SSLContext.new()
- ssl_context.ssl_version = :SSLv23
- ssl_socket = OpenSSL::SSL::SSLSocket.new(s, ssl_context)
- ssl_socket.sync_close = true
- ssl_socket.connect
- # send nickname to the server
- ssl_socket.puts "NICK linux1976\r\n"
- # send user info to the server
- ssl_socket.puts "USER linux1976 8 * :linux\r\n"
- # send registration info to the server to identify your registered nick
- ssl_socket.puts "NICKSERV identify (enter your password here)\r\n"
- # get channel to join from the user and join the channel
- print "Enter channel to join: "
- channel = gets.chomp
- ssl_socket.puts "JOIN #" + channel
- # read data from chatroom and print it to the screen
- while line = ssl_socket.gets
- puts line.chop
- if line.include? "PING :" then
- ssl_socket.puts "PONG :Linux Rocks !!"
- puts "PONG :Linux Rocks !!"
- end
- end
- # close socket when done
- ssl_socket.close
Advertisement
Add Comment
Please, Sign In to add comment