[Tutor] python and interface duplex checks

Michael Langford michael.langford at gmail.com
Thu Dec 13 05:48:52 CET 2007


Python can easily run ifconfig -a itself and then move through its
output. You can either parse out each string and then redisplay them.

If you *really* want to rewrite ifconfig, you need to call ioctl
(http://docs.python.org/lib/module-fcntl.html) and you need passing in
ioctl codes such as ones that start with SIOCGIF, such as SIOCGIFCONF
and SIOCGIFFLAGS and use the python struct module to then go through
the flags subfield. I've never looked for duplex, but I'm imagining
that it's there somewhere. You'll possibly need to parse some /proc
files as well.

This all can be done with python. Or you can just parse the ifconfig output.

          --Michael

On 12/12/07, Robert Recchia <robrecc at gmail.com> wrote:
>
>
> On Dec 12, 2007 11:01 PM, Michael Langford <mlangford.cs03 at gtalumni.org>
> wrote:
> > Most easily: If your card supports ethtool, you can just open the
> > ethtool startup config file to check there whether or not you set it
> > to duplex in the configuration (see if you have an ETHTOOL_OPTS env
> > variable).
> >
> > If you're not sure if your card can handle duplex (or you're not sure
> > the config file accurately shows what your card is set to), then you
> > can (more complicatedly) run ethtool with
> > popen(
> http://docs.python.org/lib/os-newstreams.html#os-newstreams)
> and
> > look for the status by parsing the duplex line.
> >
> > If you're not yet using ethtool, you should if you can. If you can't
> > reply back to the list and I'll delve into the older mii-tools to tell
> > you which one to hack on.
>
>
> Well what i would really like to do use python to basically display the
> interfaces ( like ifconfig -a ) and check if there is any value greater than
> 0 in either the RX error or TX errors part like below.
>
>  RX packets:588464 errors:0 dropped:0 overruns:0 frame:0
>   TX packets:714940 errors:0 dropped:0 overruns:0 carrier:0
> >
> >
> >          --Michael
> >
> >
> >
> >
> > On Dec 12, 2007 9:48 PM, Robert Recchia <robrecc at gmail.com> wrote:
> > > I was wondering can python can be used to check the duplex settings of a
> > > network card on a Linux os.
> > >
> > > --
> > > Robert Recchia
> > > _______________________________________________
> > > Tutor maillist  -  Tutor at python.org
> > > http://mail.python.org/mailman/listinfo/tutor
> > >
> > >
> >
> >
> >
> > --
> > Michael Langford
> > Phone: 404-386-0495
> > Consulting: http://www.RowdyLabs.com
> >
>
>
>
> --
> Robert Recchia


-- 
Michael Langford
Phone: 404-386-0495
Consulting: http://www.RowdyLabs.com


More information about the Tutor mailing list