By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,345 Members | 1,746 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,345 IT Pros & Developers. It's quick & easy.

Pick out ip-address

P: n/a
Can somebody help me? I want to pick-out the IP-address after my pc is
connected with the internet.
All this should work with an answering machine. When the connection
exists, the answering machine should
tell me the IP-address.
I think, the problem is in line 22 because when I set a variable named
ip_address (e.g. 123.456.789.987) it works!

1 def internetDialin(call,curr_user,config):
2 zielhost="62.104.217.40"
3 interface="ippp0"
4 # build up connection
5 c_status=os.system("ping -w 1 "+zielhost)
6 count=1
7 # wait for connection for 30 seconds
8 while ((c_status!=0) and (count<30)):
9 c_status=os.system("ping -w 1 "+zielhost)
10 count+=1
11 # output of ip-address
12 if (c_status==0):
13 cmd=os.popen('LANG=""/sbin/ifconfig'+interface)
14 lines=cmd.readlines()
15 cmd.close()
16 for l in lines:
17 index=string.find(l,"inet addr:")
18 if (index!=-1):
19 index+=10
20 rindex=string.find(l," ",index)
21#here is the problem:
22 ip_address=l[index:rindex]
23
24 cs_helpers.sayNumber(call,ip_address,curr_user,con fig)
thx
Regards,
Alex
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Mon, 16 Feb 2004 13:19:22 +0100, Alexander Födisch
<fo******@eva.mpg.de> wrote:
Can somebody help me? I want to pick-out the IP-address after my pc is
connected with the internet.


What about:
import socket
print socket.gethostbyname(socket.gethostname())

192.168.1.2

?
--
http://www.homepages.lu/pu/
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.