reduced duplicated code in ipaddress generator