import os
import sys
import re
import string
f=open('./iprange','r')
s=f.readline()
f.close()
pattern='inet addr:'+s
pattern=pattern.split('x')[0]
pattern='('+pattern+'...'+')'
os.system('ifconfig -a >> interfaces')
f=open('./interfaces','r')
s=f.readline()
while (len(s))!=0:
i=re.search(pattern,s)
if i!=None:
sp=re.split(pattern,s)[1]
ip=re.split('inet addr:',sp)[1]
break
s=f.readline()
f.close()
os.system('rm ./interfaces')
f=open('./userip','w')
f.write(ip)
f.close()
NameError;name 'ip' is not defined
I split pattern by s and store the result in sp, then I find the IP address and store the result in ip. But the error says ip is not defined - what's going on?
while s:instead ofwhile (len(s))!=0:becausebool('') == Falseandbool('any_string') == True