How to connect to remote machine and run ifconfig command

I want to connect to the Linux server ( I have username and password) ,to run ifconfig command and to store this information to the file ,which I need to download after this)

The second step is simple ,I can use Net::FTP module ,work perfectly,

But how can I connect to the server and to run ifconfig ?

Thanks for help
Who is Participating?
manav_mathurConnect With a Mentor Commented:
If you want to connect thru ssh, use Net::SSH
If you want to connect thru Telnet, use Net::Telnet

use Net::Telnet ();
my $t = new Net::Telnet (Timeout => 10,
                                      Prompt => '/bash\$ $/'
                                      Host => '');
$t->cmd('/usr/sbin/ifconfig > /path/to/file') ;
$t->close() ;
##get the /path/to/file thru Net::FTP

You must know the prompt on the server before hand and create the regex for that. The example given matches a prompt like 'bash$ '


Is telnet enabled on the server you want to connect to??
Depends on what services you have running on the remote server.

Let's assume you can connect via ssh, then you can use the Net::SSH module to connect and run the ifconfig command.

Inga_dushaAuthor Commented:
sorry that I couldn't answer before

yes ,I have telnet
use Net::SSH;
ssh('userid@yourhost','/usr/sbin/ifconfig > /path/to/file');
##Use Net::FTP to get the file back

Also, you can do away with Net::FTP because both Net::Telnet and Net::SSH provide mechanisms to capture the output of the command.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.