The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Using list account function to get IP address in php

Discussion in 'General Discussion' started by fransisco, Sep 18, 2003.

  1. fransisco

    fransisco Member

    Joined:
    Sep 8, 2003
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    USA
    Dear friends,

    I want to get the IP address of the accounts I am hosting when I call the list account function.Please can anyone help.

    Fransisco

    cPanel.net Support Ticket Number:
     
  2. Shino

    Shino Registered

    Joined:
    Oct 16, 2005
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Hi everyone, I also would like to know how I can get the ip address of an account (domain) through PHP. Thanks.
     
  3. roamingllama

    roamingllama Registered

    Joined:
    Jun 19, 2005
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Ping is the only way

    Since the IP address is not given by that function you must do the following:

    <?php

    require '/usr/local/cpanel/Cpanel/Accounting.php.inc';
    $host = "localhost";
    $user = "root";
    $accesshash = 'YOUR ACCESS HASH HERE';

    $accts = listaccts($host,$user,$accesshash,0);

    foreach($accts as $acct) {
    echo $acct[0] . " = " . gethostbyname($acct[0]) . "<br />";
    }

    ?>

    This does a lookup on the main domain for every account. If it returns the domain name back that means that the domain name could not be resolved.

    Keep inmind that depending on how many accounts you have it might take a while to load becasue it has to do a lookup on each account.

    If You want to get the IP of one specific domain you would do this:

    <?php

    require '/usr/local/cpanel/Cpanel/Accounting.php.inc';
    $host = "localhost";
    $user = "root";
    $accesshash = 'YOUR ACCESS HASH HERE';

    $accts = listaccts($host,$user,$accesshash,0);

    //If you have the user name do this
    echo gethostbyname($accts[$theUserName][0]);

    //If you have the domain name do this
    echo gethostbyname($theDomainName);

    ?>
    --------------------------------------------------
    TheRoamingLlama

    A Romaing Llama never looses it's way.
    http://www.multitaskgraphics.com
     
    #3 roamingllama, Oct 23, 2005
    Last edited: Oct 23, 2005
Loading...

Share This Page