Class: Ident

Inherits:
Object
  • Object
show all
Defined in:
lib/ident.rb

Defined Under Namespace

Modules: Response

Constant Summary collapse

KNOWN_ERRORS =
["INVALID-PORT" "NO-USER" "HIDDEN-USER" "UNKNOWN-ERROR"]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ip = nil, outbound = nil, inbound = nil, timeout = 10) ⇒ Ident

Returns a new instance of Ident.

See Also:



86
87
88
89
# File 'lib/ident.rb', line 86

def initialize(ip = nil, outbound = nil, inbound = nil, timeout = 10)
  @ip, @outbound, @inbound, @timeout = ip, outbound, inbound, timeout
  @response = nil
end

Instance Attribute Details

#inboundObject

Returns the value of attribute inbound.



82
83
84
# File 'lib/ident.rb', line 82

def inbound
  @inbound
end

#ipObject

Returns the value of attribute ip.



80
81
82
# File 'lib/ident.rb', line 80

def ip
  @ip
end

#outboundObject

Returns the value of attribute outbound.



81
82
83
# File 'lib/ident.rb', line 81

def outbound
  @outbound
end

#responseObject (readonly)

Returns the value of attribute response.



84
85
86
# File 'lib/ident.rb', line 84

def response
  @response
end

#timeoutObject

Returns the value of attribute timeout.



83
84
85
# File 'lib/ident.rb', line 83

def timeout
  @timeout
end

Class Method Details

.request(ip, outbound, inbound, timeout_after = 10) ⇒ Response::USERID, Response::ERROR

This method connects to an identd at ‘ip` and queries information for the connection `outbound`->`inbound` where `outbound` is the port a connection is coming from (usually anything >1024) and `inbound` is the port connected to, the port your service is listening on (e.g. 6667 in the case of an IRCd)

Examples:

user A connects to our server on port 23, coming from 123.123.123.123 on port 6789

Ident.request('123.123.123.123', 6789, 23)

Parameters:

  • ip (String)

    The IP of the ident server

  • outbound (Integer)

    The port from which the connection is coming

  • inbound (Integer)

    The port to which was connected

  • timeout_after (Integer) (defaults to: 10)

    The timeout, defaults to 10 seconds

Returns:

Raises:

  • (Timeout::Error)

    In case of a timeout

  • (Errno::ECONNREFUSED)

    If no identd was running at the destination host



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/ident.rb', line 116

def self.request(ip, outbound, inbound, timeout_after = 10)
  r = nil
  timeout(timeout_after) do
    t = TCPSocket.new(ip, 113)
    t.puts [outbound, inbound].join(', ')
    r = t.gets
    t.close
  end

  # in case the identd just kills our connection
  r ||= "#{outbound}, #{inbound}:ERROR:UNKNOWN-ERROR"

  r.chomp!
  Response.from(r)
end

Instance Method Details

#requestObject

See Also:



92
93
94
# File 'lib/ident.rb', line 92

def request
  @response = self.class.request(@ip, @outbound, @inbound, @timeout)
end