Net/ssh telnet set port 119 (nntp)

Following the API at:

http://rubydoc.info/gems/net-ssh-telnet/0.0.2/frames

I want to login to leafnode with something like:

s = Net::SSH::Telnet.new(:host => localhost,:port => 119)

here’s what I have so far, though:

[email protected]:~/ruby/telnet$
[email protected]:~/ruby/telnet$ ruby telnet.rb
hello
telnet.rb:8:in `’: uninitialized constant Net::SSH::Telnet
(NameError)
[email protected]:~/ruby/telnet$
[email protected]:~/ruby/telnet$ nl telnet.rb
1 require “rubygems”
2 require “net/ssh”

 3  puts "hello"


 4  s = Net::SSH::Telnet.new(
 5          "Dump_log" => "/dev/stdout",
 6          "Host" => "127.0.0.1:119",
 7  )

 8  puts "Logged in"
 9  puts s.cmd("echo hello")

10  put "started"

[email protected]:~/ruby/telnet$
[email protected]:~/ruby/telnet$ telnet localhost nntp
Trying 127.0.0.1…
Connected to localhost.
Escape character is ‘^]’.
200 Leafnode NNTP Daemon, version 1.11.8 running at localhost (my fqdn:
dur.bounceme.net)
quit
205 Always happy to serve!
Connection closed by foreign host.
[email protected]:~/ruby/telnet$
[email protected]:~/ruby/telnet$ telnet localhost 119
Trying 127.0.0.1…
Connected to localhost.
Escape character is ‘^]’.
200 Leafnode NNTP Daemon, version 1.11.8 running at localhost (my fqdn:
dur.bounceme.net)
quit
205 Always happy to serve!
Connection closed by foreign host.
[email protected]:~/ruby/telnet$

I’ve tried various ways of setting the port, but can’t figure it out.
How do you set the port?

thanks,

Thufir

On Sun, 25 Mar 2012 19:49:44 +0900, Thufir wrote:

Following the API at:

http://rubydoc.info/gems/net-ssh-telnet/0.0.2/frames

I want to login to leafnode with something like:

s = Net::SSH::Telnet.new(:host => localhost,:port => 119)

Ruby cookbook to the rescue, 14.9 “being a telnet client”:

[email protected]:~/ruby/net_telnet$
[email protected]:~/ruby/net_telnet$ ruby net.rb
Read 491 bytes; total 491
[email protected]:~/ruby/net_telnet$ nl net.rb
1 require ‘rubygems’
2 require ‘net/telnet’

 3  webserver = Net::Telnet::new('Host' => 'www.oreilly.com','Port'

=> 80,‘TelnetMode’ => false)

 4  size = 0


 5  webserver.cmd("GET / HTTP/1.1\nHost: www.oreilly.com\n") do |c|
 6    size += c.size
 7    puts "Read #{c.size} bytes; total #{size}"
 8  end

[email protected]:~/ruby/net_telnet$

just need to login to leafnode now :slight_smile:

-Thufir

On Sun, 25 Mar 2012 19:49:44 +0900, Thufir wrote:

http://rubydoc.info/gems/net-ssh-telnet/0.0.2/frames

I want to login to leafnode with something like:

Well, I don’t get it, I have no idea why the sample code doesn’t work
for
me. It appears to be a matter of ?importing? the gem correctly. What’s
the correct syntax, please? How do you know what the syntax is to ?
import? the gem correctly?

[email protected]:~/ruby/ssh$
[email protected]:~/ruby/ssh$ ruby ssh.rb
trying to connect…
ssh.rb:10:in <main>': undefined local variable or methodssh’ for
main:Object (NameError)
[email protected]:~/ruby/ssh$
[email protected]:~/ruby/ssh$ nl ssh.rb
1 require ‘rubygems’
2 require ‘net/ssh/telnet’

 3  puts "trying to connect..."



 4  s = Net::SSH::Telnet.new(
 5        "Dump_log" => "/dev/stdout",
 6        "Session" => ssh
 7  )
 8  puts "Logged in"
 9  p s.cmd("echo hello")

[email protected]:~/ruby/ssh$

thanks,

Thufir

On Sun, Mar 25, 2012 at 10:25 AM, Thufir [email protected] wrote:

On Sun, 25 Mar 2012 19:49:44 +0900, Thufir wrote:

Well, I don’t get it, I have no idea why the sample code doesn’t work for
me.

Because you’re not using the sample code?

4 s = Net::SSH::Telnet.new(
5 “Dump_log” => “/dev/stdout”,
6 “Session” => ssh
7 )

Where have you defined the ‘ssh’ for “Session”? Go back and look at
the gem’s sample code.

On Mon, 26 Mar 2012 02:43:36 +0900, Hassan S. wrote:

Well, I don’t get it, I have no idea why the sample code doesn’t work
for me.

Because you’re not using the sample code?

Pardon, I don’t understand:

http://rubydoc.info/gems/net-ssh-telnet/0.0.2/frames

example 1:

s = Net::SSH::Telnet.new(
“Dump_log” => “/dev/stdout”,
“Session” => ssh
)
puts “Logged in”
p s.cmd(“echo hello”)

That’s not my code, that’s the sample code. What I’m asking is why the
sample code, when copied, pasted, gives errors as so:

[email protected]:~/ruby/ssh$
[email protected]:~/ruby/ssh$
[email protected]:~/ruby/ssh$ ruby ssh.rb
trying to connect…
ssh.rb:10:in <main>': undefined local variable or methodssh’ for
main:Object (NameError)
[email protected]:~/ruby/ssh$
[email protected]:~/ruby/ssh$ nl ssh.rb
1 require ‘rubygems’
2 require ‘net/ssh/telnet’

 3  puts "trying to connect..."



 4  s = Net::SSH::Telnet.new(
 5        "Dump_log" => "/dev/stdout",
 6        "Session" => ssh
 7  )
 8  puts "Logged in"
 9  p s.cmd("echo hello")

[email protected]:~/ruby/ssh$

thanks,

Thufir

On Mon, 26 Mar 2012 12:49:33 +0900, Iain D. wrote:

4  s = Net::SSH::Telnet.new(
5          "Dump_log" => "/dev/stdout", 6          "Host" =>
"127.0.0.1:119",

s = Net::SSH::Telnet.new(
“Dump_log” => “/dev/stdout”,
“Host” => “127.0.0.1”,
“Port” => 119 as part

ah, ok. I thought I’d tried that, but apparently not. There’s no
login,
I just would like to pass some commands to leafnode and get the
response.

Am I not getting the output correctly?

[email protected]:~/ruby/ssh$
[email protected]:~/ruby/ssh$ ruby ssh.rb
trying to connect…

0x00000: 54 72 79 69 6e 67 20 31 32 37 2e 30 2e 30 2e 31 Trying

127.0.0.1

0x00010: 2e 2e 2e 0a …

/home/thufir/.rvm/gems/ruby-1.9.3-p125/gems/net-ssh-telnet-0.0.2/lib/net/
ssh/telnet.rb:219:in rescue in initialize': timed out while opening a connection to the host (Timeout::Error) from /home/thufir/.rvm/gems/ruby-1.9.3-p125/gems/net-ssh- telnet-0.0.2/lib/net/ssh/telnet.rb:208:ininitialize’
from ssh.rb:5:in new' from ssh.rb:5:in
[email protected]:~/ruby/ssh$
[email protected]:~/ruby/ssh$ nl ssh.rb
1 require ‘rubygems’
2 require ‘net/ssh/telnet’

 3  puts "trying to connect..."
 4  s = Net::SSH::Telnet.new(
 5          "Dump_log" => "/dev/stdout",
 6          "Host" => "127.0.0.1",
 7    "Port" => "119"
 8  )
 9  puts "Logged in"
10  putss.cmd("group comp.lang.ruby")

[email protected]:~/ruby/ssh$

thanks,

Thufir

On Sun, Mar 25, 2012 at 9:36 PM, Thufir [email protected] wrote:

That’s not my code, that’s the sample code.

Really? Here’s what I see in Example 1 –


Example 1 - pass existing Net::SSH::Session object

ssh = Net::SSH.start(“127.0.0.1”,
:username=>“test123”,
:password=>“pass456”
)
s = Net::SSH::Telnet.new(
“Dump_log” => “/dev/stdout”,
“Session” => ssh
)
puts “Logged in”
p s.cmd(“echo hello”)

What I’m asking is why the
sample code, when copied, pasted, gives errors as so:

ssh.rb:10:in <main>': undefined local variable or methodssh’

Because you didn’t copy all of it, and the variable ‘ssh’ in your broken
abbreviated test isn’t defined.

Just what the error message says, unsurprisingly :slight_smile:

4 s = Net::SSH::Telnet.new(
5 “Dump_log” => “/dev/stdout”,
6 “Host” => “127.0.0.1:119”,

s = Net::SSH::Telnet.new(
“Dump_log” => “/dev/stdout”,
“Host” => “127.0.0.1”,
“Port” => 119 as part

you’re right, when I read that last night I was a bit tired.

I’m trying to look at the corresponding API for “non-ssh” telnet, to
figure out how to login to leafnode and get the output printed to the
screen. I just get timeouts so far:

[email protected]:~/ruby/ssh$
[email protected]:~/ruby/ssh$ ruby ssh.rb
trying to connect…

0x00000: 54 72 79 69 6e 67 20 31 32 37 2e 30 2e 30 2e 31 Trying

127.0.0.1

0x00010: 2e 2e 2e 0a …

[1]+ Stopped ruby ssh.rb
[email protected]:~/ruby/ssh$
[email protected]:~/ruby/ssh$ /home/thufir/.rvm/gems/ruby-1.9.3-p125/gems/net-
ssh-telnet-0.0.2/lib/net/ssh/telnet.rb:219:in rescue in initialize': timed out while opening a connection to the host (Timeout::Error) from /home/thufir/.rvm/gems/ruby-1.9.3-p125/gems/net-ssh- telnet-0.0.2/lib/net/ssh/telnet.rb:208:ininitialize’
from ssh.rb:5:in new' from ssh.rb:5:in

[1]+ Exit 1 ruby ssh.rb
[email protected]:~/ruby/ssh$
[email protected]:~/ruby/ssh$ nl ssh.rb
1 require ‘rubygems’
2 require ‘net/ssh/telnet’

 3  puts "trying to connect..."
 4  s = Net::SSH::Telnet.new(
 5          "Dump_log" => "/dev/stdout",
 6          "Host" => "127.0.0.1",
 7    "Port" => "119"
 8  )
 9  puts "Logged in"
10  putss.cmd("group comp.lang.ruby")

[email protected]:~/ruby/ssh$
[email protected]:~/ruby/ssh$

In fact, it doesn’t even seem to be “logging in” since that put never
executes. Am I using the right API? If so, how do I get the response
which “telnet localhost nntp” brings up in the terminal?

thanks,

Thufir