Pick out ip-address

Alexander Födisch foedisch at eva.mpg.de
Mon Feb 16 07:19:22 EST 2004


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,config)


thx
Regards,
        Alex





More information about the Python-list mailing list