Man this sounds SO complex in PHP. I do it in Perl, in it's SO SIMPLE.
To get the IP address, first you must know if the package your creating DOES create it with an IP, if it DOES then do get it from here, BEFORE you create the package:
Here is the code in Perl:
my $path_to_ips = '/etc/ipaddrpool'; # That is where they are.
open(IPS,&$path_to_ips&

or dienice(&Can't open $path_to_ips for Reading: $!&

; # Open it. Or die.
seek(IPS,0,0); # find the FIRST line of the file to start.
flock(IPS,2);# Lock the file.
$thisip = &IPS&;# Get the FIRST LINE ONLY
chomp($thisip);# Kill the rest.
close(IPS);# close the file.
$thisip is now the very first IP address in the file, which is the one the Cpanel system grabs when creating an account WITH an IP address. I'd do this ALL AT THE SAME TIME, when your creating an account that way the user don't sit there a while, someone else sign up, and then they have the wrong IP address.
If it gets it AS it is creating the account, you should never have a problem with it giving the wrong IP address.
If that gives you problems, I know of one other way to do it, I THINK.
HTH,
Richard.
Sorry, had to disable the smilies- only editting I did.