Class: Ident
- Inherits:
-
Object
- Object
- Ident
- 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
-
#inbound ⇒ Object
Returns the value of attribute inbound.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#outbound ⇒ Object
Returns the value of attribute outbound.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Class Method Summary collapse
-
.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).
Instance Method Summary collapse
-
#initialize(ip = nil, outbound = nil, inbound = nil, timeout = 10) ⇒ Ident
constructor
A new instance of Ident.
- #request ⇒ Object
Constructor Details
#initialize(ip = nil, outbound = nil, inbound = nil, timeout = 10) ⇒ Ident
Returns a new instance of Ident.
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
#inbound ⇒ Object
Returns the value of attribute inbound.
82 83 84 |
# File 'lib/ident.rb', line 82 def inbound @inbound end |
#ip ⇒ Object
Returns the value of attribute ip.
80 81 82 |
# File 'lib/ident.rb', line 80 def ip @ip end |
#outbound ⇒ Object
Returns the value of attribute outbound.
81 82 83 |
# File 'lib/ident.rb', line 81 def outbound @outbound end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
84 85 86 |
# File 'lib/ident.rb', line 84 def response @response end |
#timeout ⇒ Object
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)
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
#request ⇒ Object
92 93 94 |
# File 'lib/ident.rb', line 92 def request @response = self.class.request(@ip, @outbound, @inbound, @timeout) end |