Re: Show current ip on Linux

2005-06-15 Thread David Van Mosselbeen
Sibylle Koczian wrote:

 David Van Mosselbeen schrieb:
 
 Thanks for support.
 I have read the refered page you show above. I try some piece of code
 that im have copy and paste it into a blank file that i give the name
 ip_adress.py to test it.
 
 
 THE SOURCE CODE :
 -
 
 import commands
 
 ifconfig = '/sbin/ifconfig'
 # name of ethernet interface
 iface = 'eth0'
 # text just before inet address in ifconfig output
 telltale = 'inet addr:'
 
 def my_addr():
 cmd = '%s %s' % (ifconfig, iface)
 output = commands.getoutput(cmd)
 
 inet = output.find(telltale)
 if inet = 0:
 start = inet + len(telltale)
 end = output.find(' ', start)
 addr = output[start:end]
 else:
 addr = ''
 
 return addr
 # End python code
 
 But now, it's fine to have some piece of code but this wil not work on my
 computer. I'm sure that y do somethings bad.
 To run the python script on a Linux machine. How to proceed it ?
 
 1) I have open a terminal
 2) then i type python ip_adress.py (to run the script)
 
 But nothings, i not view the current ip of my computer.
 What happend ?
 
 
 You have defined a function, but you never call this function. Running a
 script won't do anything, if this script consists only of function (or
 class) definitions.
 
 You can either
 
 - open the interactive python interpreter and type:
 import ip_adress
 ip_adress.my_addr()
 
 or, probably simpler,
 
 - add the following two lines to your script, after the definition of
 your function:
 
 if __name__ == '__main__':
  print my_addr()
 
 Then run your script just as you did before. Now you are calling the
 function and printing the value it returns.
 

It's work now :-) 
Verry thanks to all peoples that work free ont participating on
documentation and shares hers brain.

-- 
David Van Mosselbeen - DVM
http://dvm.zapto.org:
---
Fedora Core 3 User
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Show current ip on Linux

2005-06-14 Thread Sibylle Koczian
David Van Mosselbeen schrieb:
 
 Thanks for support.
 I have read the refered page you show above. I try some piece of code that
 im have copy and paste it into a blank file that i give the name
 ip_adress.py to test it.
 
 
 THE SOURCE CODE :
 -
 
 import commands
 
 ifconfig = '/sbin/ifconfig'
 # name of ethernet interface
 iface = 'eth0'
 # text just before inet address in ifconfig output
 telltale = 'inet addr:'
 
 def my_addr():
 cmd = '%s %s' % (ifconfig, iface)
 output = commands.getoutput(cmd)
 
 inet = output.find(telltale)
 if inet = 0:
 start = inet + len(telltale)
 end = output.find(' ', start)
 addr = output[start:end]
 else:
 addr = ''
 
 return addr
 # End python code
 
 But now, it's fine to have some piece of code but this wil not work on my
 computer. I'm sure that y do somethings bad.
 To run the python script on a Linux machine. How to proceed it ?
 
 1) I have open a terminal
 2) then i type python ip_adress.py (to run the script)
 
 But nothings, i not view the current ip of my computer.
 What happend ?
 

You have defined a function, but you never call this function. Running a 
script won't do anything, if this script consists only of function (or 
class) definitions.

You can either

- open the interactive python interpreter and type:
import ip_adress
ip_adress.my_addr()

or, probably simpler,

- add the following two lines to your script, after the definition of 
your function:

if __name__ == '__main__':
 print my_addr()

Then run your script just as you did before. Now you are calling the 
function and printing the value it returns.

-- 
Dr. Sibylle Koczian
Universitaetsbibliothek, Abt. Naturwiss.
D-86135 Augsburg
e-mail : [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Show current ip on Linux

2005-06-13 Thread David Van Mosselbeen
Hi,
Im a newbie in Python, and also in Fedora Core 3. (Yes, Linux is fine
man :-)

My question is : How can i rwite a script that show my current ip. If i have
more than one network card, the script must then show all used ip.

It's important that this will work on a linux. i Have rwite some piece of
code that realy work under Windows XP, but the same script wil not work on
Linux. 

Verry thanks to all vulunteers.

-- 
David Van Mosselbeen - DVM
http://dvm.zapto.org:
---
Fedora Core 3 User
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Show current ip on Linux

2005-06-13 Thread Qiangning Hong
David Van Mosselbeen wrote:
 Hi,
 Im a newbie in Python, and also in Fedora Core 3. (Yes, Linux is fine
 man :-)
 
 My question is : How can i rwite a script that show my current ip. If i have
 more than one network card, the script must then show all used ip.
 
 It's important that this will work on a linux. i Have rwite some piece of
 code that realy work under Windows XP, but the same script wil not work on
 Linux. 
 
 Verry thanks to all vulunteers.
 

How about use the shell command ifconfig | grep inet ?


-- 
Qiangning Hong

 _
( zhen so zhen when I do a chroot /path /bin/bash, i can  )
( see the processes   )
( )
( outside of the chroot zhen and i can kill those processes )
( * klieber claps for zhen zhen oh go die   )
 -
   o   \___
 v__v   o  \   O   )
 (OO)  ||w |
 (__)  || ||  \/\

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Show current ip on Linux

2005-06-13 Thread James Tanis
Previously, on Jun 13, Qiangning Hong said: 

# David Van Mosselbeen wrote:
#  Hi,
#  Im a newbie in Python, and also in Fedora Core 3. (Yes, Linux is fine
#  man :-)
#  
#  My question is : How can i rwite a script that show my current ip. If i have
#  more than one network card, the script must then show all used ip.
#  
#  It's important that this will work on a linux. i Have rwite some piece of
#  code that realy work under Windows XP, but the same script wil not work on
#  Linux. 
#  
#  Verry thanks to all vulunteers.
#  
# 
# How about use the shell command ifconfig | grep inet ?
# 

I think you mean ifconfig -a|grep 'inet '

He needs to see all the interfaces, no options will only print a help 
message. 'inet ' will get get rid of the inet6 addresses assuming he 
doesn't need those.

# 
# -- 
# Qiangning Hong
# 
#  _
# ( zhen so zhen when I do a chroot /path /bin/bash, i can  )
# ( see the processes   )
# ( )
# ( outside of the chroot zhen and i can kill those processes )
# ( * klieber claps for zhen zhen oh go die   )
#  -
#o   \___
#  v__v   o  \   O   )
#  (OO)  ||w |
#  (__)  || ||  \/\
# 
# -- 
# http://mail.python.org/mailman/listinfo/python-list
# 


---
James Tanis
[EMAIL PROTECTED]
http://pycoder.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Show current ip on Linux

2005-06-13 Thread Lee Harr
On 2005-06-13, David Van Mosselbeen [EMAIL PROTECTED] wrote:
 Hi,
 Im a newbie in Python, and also in Fedora Core 3. (Yes, Linux is fine
 man :-)

 My question is : How can i rwite a script that show my current ip. If i have
 more than one network card, the script must then show all used ip.

 It's important that this will work on a linux. i Have rwite some piece of
 code that realy work under Windows XP, but the same script wil not work on
 Linux. 

 Verry thanks to all vulunteers.


This comes up at least once a month. Google. Is. Your. Friend.

http://mail.python.org/pipermail/python-list/2005-January/258883.html

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Show current ip on Linux

2005-06-13 Thread David Van Mosselbeen
Lee Harr wrote:

 On 2005-06-13, David Van Mosselbeen [EMAIL PROTECTED]
 wrote:
 Hi,
 Im a newbie in Python, and also in Fedora Core 3. (Yes, Linux is fine
 man :-)

 My question is : How can i rwite a script that show my current ip. If i
 have more than one network card, the script must then show all used ip.

 It's important that this will work on a linux. i Have rwite some piece of
 code that realy work under Windows XP, but the same script wil not work
 on Linux.

 Verry thanks to all vulunteers.

 
 This comes up at least once a month. Google. Is. Your. Friend.
 
 http://mail.python.org/pipermail/python-list/2005-January/258883.html

Thanks for support.
I have read the refered page you show above. I try some piece of code that
im have copy and paste it into a blank file that i give the name
ip_adress.py to test it.


THE SOURCE CODE :
-

import commands

ifconfig = '/sbin/ifconfig'
# name of ethernet interface
iface = 'eth0'
# text just before inet address in ifconfig output
telltale = 'inet addr:'

def my_addr():
cmd = '%s %s' % (ifconfig, iface)
output = commands.getoutput(cmd)

inet = output.find(telltale)
if inet = 0:
start = inet + len(telltale)
end = output.find(' ', start)
addr = output[start:end]
else:
addr = ''

return addr
# End python code

But now, it's fine to have some piece of code but this wil not work on my
computer. I'm sure that y do somethings bad.
To run the python script on a Linux machine. How to proceed it ?

1) I have open a terminal
2) then i type python ip_adress.py (to run the script)

But nothings, i not view the current ip of my computer.
What happend ?

-- 
David Van Mosselbeen - DVM
http://dvm.zapto.org:
---
Fedora Core 3 User
-- 
http://mail.python.org/mailman/listinfo/python-list