473,396 Members | 1,892 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,396 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 2762
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.