I had a problem with my script too :
"i.getIpAddress()
" don't give a string so I have add this :
ipSearch = i.getIpAddress()
if ipSearch:
ipSearch=ipSearch.split('/')
if ipSearch == ip[0]:
And that works.
Thank you for your help, the function is good.