0

I have a whois service, which allows me to telnet to it and keep the telnet connection open without any time limit on it. I have to do thousands of whois through that telnet session. For example, to whois a domain, i do

echo "mydomain.com"; sleep 5| telnet whoismyserver.com 3454

I cannot run this command for thousands of whois. So is there any way that i can keep the telnet sessions open and pass arguments to it?

i want to keep a persistent telnet connection. and pass arguments to it. is that possible? for example, in above command, i can only pass argument of "echo domain" Once, but i want to pass long list of Echos, but with different intervals, and that too to only open persistent telnet sessions. i want to pass all commands one by one, at different time to one telnet session

Farhan
  • 4,210
  • 9
  • 47
  • 76
  • 2
    o.O What are you trying to do exactly, and why? – Tom O'Connor Aug 13 '13 at 13:15
  • Simply, i want to keep a persistent telnet connection. and pass arguments to it. is that possible? for example, in above command, i can only pass argument of "echo domain" Once, but i want to pass long list of Echos, but with different intervals, and that too to only open persistent telnet sessions. i want to pass all commands one by one, at different time to one telnet session – Farhan Aug 13 '13 at 13:22
  • 3
    Sure. You write a program that opens up the network connection to the remote server and then reads input from stdin and sends it to the remote server. You could probably accomplish this with `expect`, although you'd probably be better off with Python or Perl or Ruby or something. – larsks Aug 13 '13 at 13:24
  • can you provide any example of it? any implementation ?which i can see to get an idea? – Farhan Aug 13 '13 at 13:34
  • 3
    Try using a named pipe http://serverfault.com/a/407923/9517 – user9517 Aug 13 '13 at 13:39
  • Search CPAN archive for Perl module NET::Telnet and check the examples. – dsmsk80 Aug 13 '13 at 13:41
  • @Iain - post that as another answer, that's a good one that I wasn't really familiar with. – mfinni Aug 13 '13 at 13:44
  • @mfinni: tested and done. – user9517 Aug 14 '13 at 12:48

3 Answers3

5

Why can't you just run whois on your local machine and script/batch that? Or just telnet to the other system and script it there? Having to do this routed via telnet to another system seems awful.

Having said that, it is what Expect is made for (points for @larsks) , so if you have to do this, use that.

/edit - We're not your Google, but here's a start : http://expect.sourceforge.net/

mfinni
  • 35,711
  • 3
  • 50
  • 86
  • Happy to hear the reason for the downvote. I offered 3 solutions - local scripting in two places and using Expect to do what he's asking. – mfinni Aug 13 '13 at 13:30
  • i have custom application and it has this Special requirement.. its not a simple whois. – Farhan Aug 13 '13 at 13:33
  • 2
    So, as @larsks said and I repeated, use Expect. It's what it does. It opens a telnet connection that you can programatically interact with. – mfinni Aug 13 '13 at 13:35
2

You may be able to do this with a named pipe (fifo)

mkfifo my.pipe
cat >my.pipe &
cat my.fifo | telnet telnet whois.iana.org  43
echo "serverfault.com" >>my.fifo

This seems to work in as much as the echo command sends serverfault.com to the whois server. I don't have access to a server which allows persistent connections so I can't test it for more than one name. but it should be a smop to read your domain names and echo them to the pipe.

If you want to collect the output in a file then just redirect stdout

cat my.fifo | telnet telnet whois.iana.org  43 >some.output.file
user9517
  • 114,104
  • 20
  • 206
  • 289
  • its fine, but i am not able to automate this process through bash profile. as the time limit for which telnet remains open, is 30 min, on server. so i very hard to track and keep telnet alive :( – Farhan Aug 27 '13 at 15:07
1

Search CPAN archive for Perl module NET::Telnet and check the examples.

use Net::Telnet ();
$t = new Net::Telnet (Timeout => 10,
                      Prompt => '/bash\$ $/');
$t->open($host);
$t->login($username, $passwd);
@lines = $t->cmd("who");
print @lines;
dsmsk80
  • 5,757
  • 17
  • 22