[j-nsp] sample junoscript code to retrieve BGP AS paths

John Kristoff jtk at ultradns.net
Wed Sep 13 17:43:44 EDT 2006


Below is a link to some sample code, that is really just an initial
crack at interrogating a Juniper router in order to output the set of
active BGP AS paths for one or more addresses/netblocks.  I've barely
tested this.  It seems to work for a few common cases, but your mileage
may vary.  This is being provided to the community in the hopes that
someone may find it useful to build better junoscript-based tools and
make them available so that I may in turn borrow back from them.  The
thing I had trouble finding much guidance on was accessing the XML::DOM
object directly.  I'm still a little confused by it, but I seemed to
have brute forced my way to a solution.

Be sure to read through the comments in the code if you try to use this.
For example, you'll see that I ended up modifying junoscript's Device.pm
in order to handle authentication failures myself, which you may want to
do as well.  In addition, enabling taint requires working around or
fixing junoscript's Access.pm, which Juniper will hopefully do soon.
Standard disclaimer applies, I don't know Perl, I know Combat Perl.

A sample run looks like this:

  $ echo 192.0.2.1 | ./getaspath -rroutername.example.net 2> /dev/null
  login: user
  password:
  192.0.2.1|65535 65534 65532 I

Note, I pipe stderr to null, because of all the warnings junoscript
generates (hopefully those will be fixed by Juniper soon too).  If
you're ok with hard coding some auth credentials you can obviously use
this in an automated fashion, perhaps as part of some AS path-based
reporting.

  <http://layer9.com/~jtk/software/getaspath>

John


More information about the juniper-nsp mailing list