I'm a "learn by example" guy, so that's how I'll teach, but first, a little about objects in Perl. If you want to just get to the guts of NTCI, look for another doc. This one will be a snoozer if you're familiar with Perl objects.

Objects in Perl, like any other language, are defined by modules like IOS.pm, which defines the characteristics and methods of the object. Each object also inherits characteristics and methods from their parent, so, since NTCI is a child of Net::Telnet::Cisco, it has all the characteristics and methods of its parent.

It's not a coincidence that NTCI, being a child of Net::Telnet::Cisco, is in a module called IOS and called Net::Telnet::Cisco::IOS. Notice the colons (::) between the words in the name? That tells you what the parents of the modules are. So, do you think that Net::Telnet::Cisco is a child of Net::Telnet? Yes, it is. And Net::Telnet is a child of Net, so, if we remember inheritance, NTCI has the characteristics of Net, Net::Telnet, and Net::Telnet::Cisco. What does that mean for you? It means that you should read up on Net::Telnet::Cisco, Net::Telnet, and Net to use NTCI fully.

Objects also require instantiation, which means to create an instance of the object to use. This is done by calling the "new" method to create an instance that you can manipulate and use. Let's try it.

use Net::Telnet::Cisco::IOS;
$conn = Net::Telnet::Cisco::IOS->new( Host => "routername" );
The first line imports the NTCI library. This is nothing new to Perl.

The second line creates a variable called "$conn" which is an instance of NTCI that you will use. In this case, we're trying to connect to a host called "routername", so we have to tell the library by using the Host option of the object hash. Note: Hashes are beyond the scope of this document. Google has plenty of docs about it. Just look for "perl hashes" or something.

All we've done so far is to create an object (basically, just a memory location). It hasn't done a thing yet. What's the first thing you do when you want to get into a router? How about log in?

$conn->login( Name => "username", Password => "password");
This line actually logs into the device. Since we created an object called "$conn" to connect to it, we simply run methods against the object. This is done with the "->" symbol. The line says to take the object called "$conn" and run the "login" method on it with the listed parameters. In our case, we logged in as "username" with the password of "password". Now we can actually do stuff.

Let's do something simple. How about get the IOS version of the device we're on. We do this with NTCI's "getIOSVer()" method.

$iosver = $conn->getIOSVer();
This line calls the "getIOSVer()" method and puts it's value into a variable claled "$iosver". Pretty straight forward, I think. Now for something more complicated.

How about we get all the interfaces on the box? This is done with the "listInts" method.

@ints = $conn->listInts();
This line puts the value of the "listInts()" method and puts it in an array called "@ints". Now, what do you do with the array? Well, you do whatever you want to do. How about just listing all of them to the screen?
foreach $interface ( @ints )  {
	print "$interface\n";
This line just prints all the interfaces, one per line. If you don't know what's going on, look for Perl documentation somewhere. Try a Google search on "perl tutorial" to start.

Always remember to close your connection when you're done with a device so you don't waste resources. The syntax is easy.

Those are the basics. Obviously, NTCI does more than get the IOS and interfaces, so explore the documentation for the list of all the methods your can run. If you think NTCI should do more or are having a hard time understanding what's going on, let me know via a Support Request.
© 2005-2006 -- Aaron Conaway