473,320 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Perl shell as Telnet

35
Hi all,

I am a newbie in Perl. I am wondering if anyone has ever written a perl script which can be run as telnet. Could you please give me some hint or where to start to look at?

Thanks!!

Casy
Oct 20 '08 #1
13 2760
KevinADC
4,059 Expert 2GB
I don't understand what you mean by "run as telnet" but see if anything here helps you:

http://search.cpan.org/search?query=telnet&mode=all
Oct 20 '08 #2
casybay
35
Sorry for the confusion. I mean a command that establish a connection to a server as telnet does.
I don't understand what you mean by "run as telnet" but see if anything here helps you:

http://search.cpan.org/search?query=telnet&mode=all
Oct 20 '08 #3
KevinADC
4,059 Expert 2GB
You use sockets to connect to remote computers. Look into IO::Socket, it comes with perl.
Oct 20 '08 #4
casybay
35
Thanks.
Just finished the coding. I did this because I would like to see what will happen if I keep establishing new socket with a server and keep sending it requests. Will I be blocked or any other consequence? Or what are the reasons a server limits connections to it.
Oct 20 '08 #5
KevinADC
4,059 Expert 2GB
Thanks.
Just finished the coding. I did this because I would like to see what will happen if I keep establishing new socket with a server and keep sending it requests. Will I be blocked or any other consequence? Or what are the reasons a server limits connections to it.
I don't know the answer to those questions.
Oct 20 '08 #6
Icecrack
174 Expert 100+
Thanks.
Just finished the coding. I did this because I would like to see what will happen if I keep establishing new socket with a server and keep sending it requests. Will I be blocked or any other consequence? Or what are the reasons a server limits connections to it.
the answer is ask the server provider, they are the ones who know if there is a limit on a server connection.
Oct 20 '08 #7
casybay
35
Okay, then let's go back to perl. How do I generate multiple (i) threads that each binds to a TCP connection to the same server (I already have this code done)? The value of i won't know until runtime pass at argument.
Thanks!
Oct 21 '08 #8
KevinADC
4,059 Expert 2GB
Okay, then let's go back to perl. How do I generate multiple (i) threads that each binds to a TCP connection to the same server (I already have this code done)? The value of i won't know until runtime pass at argument.
Thanks!
I have no idea how to do that, sorry, maybe Icecrack has a suggestion or further advise.
Oct 21 '08 #9
Icecrack
174 Expert 100+
Okay, then let's go back to perl. How do I generate multiple (i) threads that each binds to a TCP connection to the same server (I already have this code done)? The value of i won't know until runtime pass at argument.
Thanks!

as we can't see any code how are we suppose to help answer that question and if you show code then i can see how to do it with your code.
Oct 21 '08 #10
casybay
35
Em..I don't have it with me now. But let's just say I have a sub A, and I want to bind this sub to multiple threads. The number of threads won't know until I pass an argument in run time.
Oct 21 '08 #11
Icecrack
174 Expert 100+
Em..I don't have it with me now. But let's just say I have a sub A, and I want to bind this sub to multiple threads. The number of threads won't know until I pass an argument in run time.
we will wait till you get code posted.
Oct 21 '08 #12
casybay
35
The br_tcp.pl code following is the one that I want to binds to multiple threads.
It may be dumb to ask, if I put the following code in a loop, since the file handle is the same (F) each time, does that mean the socket is the same?
Thanks.
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. #test.pl
  3. use Socket;
  4. require "br_tcp.pl";
  5.  
  6. my $ser_nam;
  7.  
  8. # connect to server, F is the file handler, first argument is server name, second is port number
  9. if (open_TCP(F, $ARGV[0], $ARGV[1]) == undef) {
  10.   print "Error connecting to server at $ARGV[0] port $ARGV[1].\n";
  11.   exit(-1);
  12. }else {
  13.     $ser_nam = $ARGV[0];
  14. }
  15.  
  16. $req = <STDIN>;
  17. $hos = <STDIN>;
  18. print F "$req$hos\n\n";
  19. print $_ while (<F>);
  20.  
  21. close(F);
  22.  
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2. #br_tcp.pl
  3. use Socket;
  4.  
  5. ##############################################################
  6.  
  7. # socket connection
  8. # Given ($f, $dest, $port) return 1 if successful, undef when unsuccessful.
  9.  
  10. ###############################################################
  11. sub open_TCP{
  12.     #get parameters: file(which file handle to associate with the socket),destination(a host name or IP address), port
  13.     #specify wether the socket should be stream-oriented or record-oriented. For HTTP transactions, scokets are stream-oriented connections
  14.     #running TCP over IP, so HTTP-based applications must associate these characteristics with a newly created socket.
  15.     #put f, dest and port into variable 
  16.     my ($f,$dest,$port) = @_;
  17.  
  18.     #PF_INET indicates the Internet Protocol while getprotobyname('tcp') indicates that the TCP runs on top of IP.
  19.     #SOCK_STREAM indicates that the sockets is stream-oriented
  20.     #my $proto = getprotobyname('tcp');
  21.     socket($f,PF_INET,SOCK_STREAM,getprotobyname('tcp'));
  22.  
  23.     #The Socket::sockaddr_in() routine accpets a port number and a 32-bit IP address; Socket::inet_aton() translates a hostname string or 
  24.     #dotted decimal string to a 32-bit IP address.
  25.     my $sin = sockaddr_in($port,inet_aton($dest));
  26.     connect($f,$sin) || return undef;
  27.  
  28.     my $old_fh = select($f);
  29.     #don't buffer output
  30.     $| = 1;   
  31.     select($old_fh);
  32.     1;
  33. }
  34. 1;
  35.  
Oct 21 '08 #13
Icecrack
174 Expert 100+
The br_tcp.pl code following is the one that I want to binds to multiple threads.
It may be dumb to ask, if I put the following code in a loop, since the file handle is the same (F) each time, does that mean the socket is the same?
Thanks.
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. #test.pl
  3. use Socket;
  4. require "br_tcp.pl";
  5.  
  6. my $ser_nam;
  7.  
  8. # connect to server, F is the file handler, first argument is server name, second is port number
  9. if (open_TCP(F, $ARGV[0], $ARGV[1]) == undef) {
  10.   print "Error connecting to server at $ARGV[0] port $ARGV[1].\n";
  11.   exit(-1);
  12. }else {
  13.     $ser_nam = $ARGV[0];
  14. }
  15.  
  16. $req = <STDIN>;
  17. $hos = <STDIN>;
  18. print F "$req$hos\n\n";
  19. print $_ while (<F>);
  20.  
  21. close(F);
  22.  

try changing:
Expand|Select|Wrap|Line Numbers
  1. print $_ while (<F>);
to :
Expand|Select|Wrap|Line Numbers
  1. while (<F>)
  2. {
  3. print $_;
  4. }
Oct 21 '08 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Lionel | last post by:
Hi all, I would like having more informations on how we could exchange informations and/or objects between PERL and JAVA. We have a Java programs that open, maintain and close telnet...
2
by: Mohsin | last post by:
Hi all, I have a perl program which makes a user exit to the O/S (unix, solaris) to issue a O/S command. I know that the shell it invokes is NOT a korn shell, because I captured the shell info...
3
by: Pete | last post by:
Is there any possiblity of writing an Access or Visual Basic application that provides a method of sharing the window focus between Access and the Shell application? i.e....
2
by: Kai Thorsrud | last post by:
Hi I'm currently into converting a perl linux app into a .Net windows service. The application monitors our syslog log files to capture i.p adress changes on some of our routers having dynamic...
8
by: Stephen Long | last post by:
I'm looking for information on how i can open a remote command shell <cmd.exe> on a remote pc and perform basic DOS/Shell commands .. TIA Steve
4
by: Patricia Mindanao | last post by:
I want to call cgi perl scripts on my web hosters server from my HTML web pages (on the the web hosters server too). It occurs sometimes (especially during development phase) that these cgi-perl...
2
by: johnyboy1230987 | last post by:
I am running my perl on linux trying to connect to window via telnet. How can I overcome the "Mode:" prompt? as you know when you telnet a window box you will be prompted with "Mode" I tried...
6
by: sherrygomindes | last post by:
Hi I have written a perl script using the Telnet module. I need to remotely login in from one windows XP machine to another XP machine. But i get errors which i can't figure out the reason....
9
by: ravimath | last post by:
Hi all , I have written script to view some router output , my script executes successfuly , but does'nt show any output, why ?, it always shows output as 1. use Net::Telnet; use Term::ReadKey;...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.