Enough people have asked me for a copy of that script that I will just post it to the mailing list. Note that there are several ways to find the speed of a port. Since they are all in a script, it really does not matter which set you use, just so it is complete. NB: if a port is set to "autonegotiate", all five checks respond as "1", so the output will be that all speeds are enabled on a particular port. btw, this is in reference to > Does anyone know of a single command that will tell me the speed of an > interface? I have a shell script with ndd commands to query the speed, > but that shell script queries each interface 5 times (10/half, 10/full, > 100/half, 100/full, autonegotiate) and so it is much harder to put in > cron. TIA. > > The answer: > > [...] > I have written a perl > script that gets all interface names on a machine and then runs the > appropriate ndd commands to determine the speed of all interfaces. > > +-----------------------------------------------------------------------+ > | Christopher L. Barnard O When I was a boy I was told that | > | cbarnard@tsg.cbot.com / \ anybody could become president. | > | (312) 347-4901 O---O Now I'm beginning to believe it. | > | http://www.cs.uchicago.edu/~cbarnard --Clarence Darrow | > +----------PGP public key available via finger or PGP keyserver---------+ ------8<------- #!/usr/local/bin/perl # ### script to report the current network speed of all interfaces. ### ### Christopher L. Barnard ### April 2002 { ### ### You have to be root to do these ndd commands. ### $login = getpwuid($<); if ( $login ne "root" ) { printf ("You have to be root to do this.\n"); exit 3; } ### ### get the name of all of the interfaces on this machine (from ifconfig) ### and put them into an array. ### @ifconfigline = ( `/sbin/ifconfig -a | /usr/bin/grep "flags=" ` ); ### ### Now chop off all but the interface name (the first part of each line) ### for ($i=0; $i<=$#ifconfigline; $i++) { @interface[$i] = split(/[:]/,@ifconfigline[$i]); } ### ### Next, separate the interface name from the interface number. ### For simplicy, I am assuming that the last digit is the number and ### all other characters are the interface name. Of course, this will ### not work if there are more than ten interfaces on a machine that are ### all of the same type. ### ### start counting at one to discard the 0th interface, which will be lo0. ### for ($i=1; $i<=$#ifconfigline; $i++) { @intnumber[$i] = substr (@interface[$i], -1, 1); chop @interface[$i]; $tmpintname = substr(@interface[$i],0); @intname[$i] = "/dev/" . $tmpintname; printf ("@intname[$i]@intnumber[$i]: "); ### ### now do the ndd commands on the interface. If the ndd command ### returns "1", then that is what the interface is set to. The "chop" ### command is because ndd returns a number followed by a <cr> to make ### it more readable; all I care about is the number. ### if ( @intname[$i] eq "/dev/le" ) { printf (" le interfaces can only do 10/half.\n"); } else { `/usr/sbin/ndd -set @intname[$i] instance @intnumber[$i]`; $return=`/usr/sbin/ndd -get @intname[$i] adv_autoneg_cap`; chop $return; if ( "$return" eq "1" ) { printf(" autonegotiating"); } $return=`/usr/sbin/ndd -get @intname[$i] adv_10hdx_cap`; chop $return; if ( "$return" eq "1" ) { printf(" 10mbit/sec, half duplex"); } $return=`/usr/sbin/ndd -get @intname[$i] adv_10fdx_cap`; chop $return; if ( "$return" eq "1" ) { printf(" 10mbit/sec, full duplex"); } $return=`/usr/sbin/ndd -get @intname[$i] adv_100hdx_cap`; chop $return; if ( "$return" eq "1" ) { printf(" 100mbit/sec, half duplex"); } $return=`/usr/sbin/ndd -get @intname[$i] adv_100fdx_cap`; chop $return; if ( "$return" eq "1" ) { printf(" 100mbit/sec, full duplex"); } printf("\n"); } } } _______________________________________________ sunmanagers mailing list sunmanagers@sunmanagers.org http://www.sunmanagers.org/mailman/listinfo/sunmanagersReceived on Mon Apr 22 12:35:24 2002
This archive was generated by hypermail 2.1.8 : Thu Mar 03 2016 - 06:42:41 EST