Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Derp! Thanks! That extra line of "open2socket" was what was what was causing the problems. Don't know how I missed that creeping in there.

As for SSH/830 - It looks like the RFC says it must go into NETCONF subsystem when connected on port 830, but should be allowed access to NETCONF when connected to on other ports. Looks like Cisco's implementation is to have the user connect on port 22 and then call the susbsystem

So, once I got rid of that extra line, it seems to be connecting just fine. I see the banner and logon prompt, and then the remote device's hello message.

I had issues figuring out how to send queries and receive replies using open2socket, but got it to work using open_ex. Here's what I currently have:

#!/usr/bin/perl ## CALL MODULES use strict; use warnings; use Net::OpenSSH; ## SET VARIABLES my $host = 'host'; my $user = 'user'; my $pass = 'pass'; my ($ssh, $out, $in, $pid); my ($message); ## OPEN THE SSH SESSION $ssh = Net::OpenSSH->new($host, user=>$user, password=>$pass); $ssh->error and die "unable to connect to remote host: " . $ssh->error +; ($out, $in, undef, $pid) = $ssh->open_ex( { stdin_pipe=>1, stdout_pipe +=>1, ssh_opts=>'-s'},'xmlagent' ) or die "open_ex failed: " . $ssh->e +rror; ## SEND THE CLIENT HELLO $message = qq~ <?xml version="1.0"?> <nc:hello xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"> <nc:capabilities> <nc:capability>urn:ietf:params:xml:ns:netconf:base:1.0 +</nc:capability> </nc:capabilities> </nc:hello> ]]>]]>~; print $out $message; ## SEND THE QUERY FOR THE ARP TABLE $message = qq~ <?xml version="1.0" encoding="UTF-8"?> <nf:rpc message-id="1" xmlns="http://www.cisco.com/nxos:1.0:arp" xmlns +:nf="urn:ietf:params:xml:ns:netconf:base:1.0"> <nf:get> <nf:filter type="subtree"> <show> <ip> <arp/> </ip> </show> </nf:filter> </nf:get> </nf:rpc> ]]>]]>~; print $out $message; ## PRINT THE RESULTS while (<$in>) { print; last if $_ =~ m/\/nf:rpc-reply/; }; waitpid($pid, 0); exit;

And, here's a snippet of the results

<ROW_adj> <intf-out>Vlan852</intf-out> <ip-addr-out>10.7.252.191</ip-addr-out> <time-stamp>00:00:50</time-stamp> <mac>0050.56ab.2d52</mac> </ROW_adj> </TABLE_adj> </ROW_vrf> </TABLE_vrf> </__readonly__> </__XML__OPT_Cmd_arp_show_adj_cmd___readonly__> </__XML__OPT_Cmd_arp_show_adj_cmd_ip-address> </arp> </ip> </show> </nf:data> </nf:rpc-reply>

My main problem right now is that I expected the "last" statement of the while loop to find the last line ("/nf:rpc-reply") of the switch's reply and move on to whatever we wanted to do next (In this case, close everything down). But, instead it seems to hang there, so I must still be missing something).

And, would open2socket be better than open_ex? And if so, can you show a sample of how to print to and read from it? I tried a couple different ways, but wasn't getting it


In reply to Re^4: SSH to remote subsystem (Net::OpenSSH?) by sojourner9
in thread SSH to remote subsystem (Net::OpenSSH?) by sojourner9

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (4)
    As of 2017-12-11 14:13 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      What programming language do you hate the most?




















      Results (297 votes). Check out past polls.

      Notices?