How to connect to remote machine and run ifconfig command

Posted on 2005-04-18
Last Modified: 2008-02-26
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
Question by:Inga_dusha
    LVL 16

    Expert Comment

    Is telnet enabled on the server you want to connect to??
    LVL 48

    Expert Comment

    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.


    Author Comment

    sorry that I couldn't answer before

    yes ,I have telnet
    LVL 16

    Accepted Solution

    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$ '


    LVL 16

    Expert Comment

    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.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (…
    Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now