473,732 Members | 2,043 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Connecting to linux machine using Telnet Module.

8 New Member
Hi,

The below code is used to connect to the remote machine using Telnet module in perl.

Expand|Select|Wrap|Line Numbers
  1. use Net::Telnet;
  2. use Net::Ping;
  3. $telnet = new Net::Telnet (Timeout=>10,Errmode=>'die');
  4.  
  5. open (FILE,"C:/start.txt") or die ("Unable to open start.txt");
  6. while(<FILE>)
  7.     $cnt++ if !/^\s+?$/;
  8. close(FILE);
  9.  
  10. open fin,"C:/start.txt" or die $!;  
  11. my @data=<fin>;
  12. close(fin);
  13.  
  14. for(my $s=0;$s<$cnt;$s++)
  15. {
  16. $addr="$data[$s]"; 
  17. $addr =~s/^\s+//;
  18. $addr =~s/\s+$//;
  19. $p=Net::Ping->new("tcp");
  20.  
  21. if($p->ping($addr))
  22. {
  23. my $server ="$addr";
  24. $telnet->open($server);
  25. $telnet->waitfor('/login:/');
  26. $telnet->print('root');
  27. $telnet->waitfor('/password:/');
  28. $telnet->print('password');
  29. print $telnet->cmd("uname -a|tr -s ' '|cut -f1 -d ' '");
  30. }
  31. }

The Start.txt file contains the list of IP Address as shown below,

Expand|Select|Wrap|Line Numbers
  1. 192.168.**.1
  2. 192.168.**.20
  3. 192.168.**.25
The script will read the IP Address from the file start.txt one by one,by executing the given UserID and Password to produce the output.Suppose the UserID and Password for any of these Machine is wrong then it is exiting out of the Script without reading the Next IP Address.I want the Solution like,if the password is wrong for any of the machine then my script should read the next IP Address from the file instead of exiting out of the script.Please any one help me in this........... ..

Thanks in advance.


Regard's,
Thamayanthi
May 26 '08 #1
2 2994
gpraghuram
1,275 Recognized Expert Top Contributor
The default errormode is die in net::telnet.
You can make use of errmode() function in that module to get around that.
Read the documentation for more info about errmode.

Raghuram
May 27 '08 #2
thamayanthi
8 New Member
Thanks for your reply...
Now,my Script is woking fine........
May 29 '08 #3

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

Similar topics

2
6974
by: Bob | last post by:
Hi, I have a website in a Linux/Apache shared hosting environment and have been given access to the MySQL server running on the same machine. To access this database from PHP, I have to call mysql_connect(host, user, password) where the password is hardcoded into my PHP source file in clear text. I see two security problems with this:
4
3626
by: Bart van den Burg | last post by:
Hi I'm using mysql-server 4.0.13-3 on Debian. I wish to be able to connect to that server using a mysql frontend from my other computer, which is a Win32 box. However, when I try "telnet 192.168.1.40 3306" on the win32 box, or "telnet localhost 3306" on the host box, I get connection refused. Can someone give me, or point me to a step-by-step explaination on how this is achieved?
5
4601
by: Maurice LING | last post by:
Hi, I've been using FB1.5 and access the database using Kinterbasdb + Python. My connection is established using kinterbasdb.connect() method and the parameters host, dns, database, user, password are all defaulted to 'None'. On my own machine running Mac OSX 10.3, I can connect using the following: host = 'localhost' database = '<my path to FB database>'
4
2699
by: John Owens | last post by:
Hi, I'm looking for a plugin for Visual Studio .NET or another IDE etc that would allow me to develop on Windows but have the compiler and debugger and code run on Linux. e.g. Code using Windows Build ( Behind the scenes: FTP updated files over to Linux and then compile
12
2787
by: Ann Marinas | last post by:
Hi all, I would like to ask for some help regarding separating the asp.net webserver and the sql server. I have created an asp.net application for a certain company. Initially, we installed both the iis and sql server in a single machine. Not too long ago, the machine had some hardware problems, and management has decided to purchase new servers, for both asp.net and sql server.
10
1431
by: Mike Collins | last post by:
I am trying to connect to a 2003 Server from an ASP.Net page and am getting the following error message. Can someone please help get me started on how to track and fix this error? The code I am using is below the error I am getting. Error: System.Data.SqlClient.SqlException: SQL Server does not exist or access denied. at System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction) at...
9
2702
by: RvGrah | last post by:
After much hair-pulling, I've finally found the answer to a problem that many are fighting with, difficulty connecting from Sql 2005 Server Management or VS2005 to a remote Sql Server running Sql 2000. In my case the server I couldn't reach was across a vpn connection, behind ISA server 2000, (which had port 1433 open). The answer was in this post:...
2
20849
jwwicks
by: jwwicks | last post by:
C/C++ Programs and Debugging in Linux This tutorial will give you a basic idea how to debug a program in Linux using GDB. As you are aware Visual Studio doesn’t run on Linux so you have to use some of the tools provided on the command-line. If you hate the command line tools, get over it since you’re bound to be using them at some point in your career. All commands in Linux ARE case sensitive so capital letters are different from lowercase...
6
5511
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. Please someone help me its very very urgent. here is my code: #!/usr/bin/perl -w
0
8944
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8773
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9445
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9306
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9180
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3259
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.