Skip to content

Instantly share code, notes, and snippets.

@bdrewery
Created February 23, 2011 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdrewery/840838 to your computer and use it in GitHub Desktop.
Save bdrewery/840838 to your computer and use it in GitHub Desktop.
Ident client (RFC 1413)
#! /usr/bin/env ruby
# ./ident.rb HOST PORT
# Get the username of the remote port
require 'socket'
require 'timeout'
hostname = ARGV[0]
port = ARGV[1]
timeout_interval = ARGV[2] || 5
begin
timeout(timeout_interval.to_i) do
dest_socket = TCPSocket.open(hostname, port)
ident_socket = TCPSocket.open(hostname, 113)
local_port = dest_socket.addr[1]
ident_socket.puts "#{port}, #{local_port}"
p ident_socket.gets
end
rescue Timeout::Error
puts "Timeout checking ident for #{hostname}:#{port}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment