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,377
  • 12
  • 56
  • 87

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
  • 36,892
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
  • 117,122
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
  • 6,047