diff --git a/lib/net/telnet.rb b/lib/net/telnet.rb index eb69b69..46cb83f 100644 --- a/lib/net/telnet.rb +++ b/lib/net/telnet.rb @@ -182,6 +182,7 @@ class Telnet # host = Net::Telnet::new( # "Host" => "localhost", # default: "localhost" # "Port" => 23, # default: 23 + # "Source" => 192.168.1.1 # default: nil # "Binmode" => false, # default: false # "Output_log" => "output_log", # default: nil (no output) # "Dump_log" => "dump_log", # default: nil (no output) @@ -201,6 +202,10 @@ class Telnet # # Port:: the port to connect to. Defaults to 23. # + # Source:: the local IP address, or hostname from which to connect to + # remote host, as a String. + # Defaults to nil, system will choose best "route". + # # Binmode:: if false (the default), newline substitution is performed. # Outgoing LF is # converted to CRLF, and incoming CRLF is converted to LF. If @@ -274,6 +279,7 @@ def initialize(options) # :yield: mesg @options = options @options["Host"] = "localhost" unless @options.has_key?("Host") @options["Port"] = 23 unless @options.has_key?("Port") + @options["Source"] = nil unless @options.has_key?("Source") @options["Prompt"] = /[$%#>] \z/n unless @options.has_key?("Prompt") @options["Timeout"] = 10 unless @options.has_key?("Timeout") @options["Waittime"] = 0 unless @options.has_key?("Waittime") @@ -344,10 +350,10 @@ def @dumplog.log_dump(dir, x) # :nodoc: begin if @options["Timeout"] == false - @sock = TCPSocket.open(@options["Host"], @options["Port"]) + @sock = TCPSocket.new(@options["Host"], @options["Port"], @options["Source"]) else Timeout.timeout(@options["Timeout"], Net::OpenTimeout) do - @sock = TCPSocket.open(@options["Host"], @options["Port"]) + @sock = TCPSocket.new(@options["Host"], @options["Port"], @options["Source"] ) end end rescue Net::OpenTimeout