newb Q

Toy gee308 at mediaone.net
Sat Jul 22 20:42:59 EDT 2000


Thanks for the tips.
I was trying to analyze your code.  Which line is the line that is 'print results
from ifconfig'?  How do I make is so I can say 'x = ifconfigresults'

Thanks


Matthew Dixon Cowles wrote:

> In article <39794752.D54A50CD at mediaone.net>, Toy <gee308 at mediaone.net>
> wrote:
>
> > Thanks for showing me how to do that.  I tried to edit something, but it
> > didn't work, I'll show you:
> >
> >
> > def getMyAddr():
> >   object = raw_input(Which device is connect to the internet(i.e. ppp0, eth0,
> > ne3: ")
> >   p=os.popen("/sbin/ifconfig",object)
> >
> > Is it possible to do that?
>
> It's possible to do something like that. The argument to os.popen (and
> to os.system) needs to be a character string. So you need to build up
> the string so that it looks just like what you'd type at the keyboard.
> The string concatenation operator is +, so you'd do something like:
>
> dev=raw_input("Device name? ")
> p=os.popen("/sbin/ifconfig "+dev)
>
> > Will it work with os.system?  What are the differences bewteen using
> > os.popen and os.system?
>
> os.system is similar to os.popen in that both execute a command of the
> sort that you'd ordinarily type at a shell prompt. They're different in
> that os.system just executes that command and if the command produces
> any output, it's printed in your shell window, while os.popen (if you
> accept its default) returns a file-like object that you can use to read
> the output that the command produces and use it in your program.
>
> > BTW, I only compared OpenBSD 2.7, Linux 2.2.15, and FreeBSD 4.0, but it seems
> > if you do the string search  on ifconfig with find text on 1 line beginning
> > with inet and ending with mask, It looks like you can get the IP from those 3
> > machines.(of coure I still can't write some code to actually do it).
>
> In situations like this, it's generally possible to find some mechanism
> that works almost all of the time. It's also almost always the case
> that eventually something that you were depending on will change and
> you'll have to fix your code.
>
> Regards,
> Matt




More information about the Python-list mailing list