Community Forums
Connect with us on LinkedIn
Community Notice
+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Member
    Join Date
    Mar 2009
    Posts
    11

    Default Getting the IP address of the server

    What's the preferred way of getting the IP address of a server via the API and only when connecting via port 2082/83 (not WHM)?

  2. #2
    Super Moderator This forum account has been confirmed by cPanel staff to represent a vendor. chirpy's Avatar
    Join Date
    Jun 2002
    Location
    Go on, have a guess
    Posts
    13,495

    Default

    Which IP address are you after? The servers main IP address or the IP address of the site you're running the script under? Could you use the apache SERVER_ADDR environment variable?
    Jonathan Michaelson

    Need your cPanel servers secured and tuned?
    cPanel Server Configuration, Security, Recovery and Antivirus/AntiSpam Services
    Developers of the most effective (and free) Firewall & Security Solution for cPanel Servers - csf
    http://www.configserver.com

  3. #3
    Member
    Join Date
    Mar 2009
    Posts
    11

    Default

    Actually, I'm accessing the API remotely via Javascript. The IP address that I'm trying to get is the IP address of the server on which Cpanel is running.

  4. #4
    cPanel Staff cPanelMatt's Avatar
    Join Date
    Apr 2005
    Location
    Houston, TX
    Posts
    409

    Default

    This can be done via the API2 function StatsBar::stats

    it needs to be called like the following:

    https://DOMAIN:2083/xml-api/cpanel?u...panelaction%3E

    or in something that's actually readable..

    Code:
    <cpanelaction>
      <module>StatsBar</module>
      <func>stat</func>
      <apiversion>2</apiversion>
      <args>
         <display>sharedip</display>
      </args>
    </cpanelaction>
    Matt Dees
    Integration Developer
    cPanel, Inc.
    cPanel Integration Blog

  5. #5
    Member
    Join Date
    Mar 2009
    Posts
    11

    Default

    Thanks, Matt! That worked. I was using "dedicatedip" and on some servers it wasn't returning an ip address.

  6. #6
    Registered User
    Join Date
    Aug 2009
    Posts
    2

    Default

    function countryCityFromIP($ipAddr)
    {
    //function to find country and city from IP address
    //Developed by Roshan Bhattarai Roshan Bhattarai's Blog - A blog about PHP, Ajax, JavaScript, CSS, Web 2.0 and Web Development

    //verify the IP address for the
    ip2long($ipAddr)== -1 || ip2long($ipAddr) === false ? trigger_error("Invalid IP", E_USER_ERROR) : "";
    $ipDetail=array(); //initialize a blank array

    //get the XML result from hostip.info
    $xml = file_get_contents("http://api.hostip.info/?ip=".$ipAddr);

    //get the city name inside the node <gml:name> and </gml:name>
    preg_match("@<Hostip>(\s)*<gml:name>(.*?)</gml:name>@si",$xml,$match);

    //assing the city name to the array
    $ipDetail['city']=$match[2];

    //get the country name inside the node <countryName> and </countryName>
    preg_match("@<countryName>(.*?)</countryName>@si",$xml,$matches);

    //assign the country name to the $ipDetail array
    $ipDetail['country']=$matches[1];

    //get the country name inside the node <countryName> and </countryName>
    preg_match("@<countryAbbrev>(.*?)</countryAbbrev>@si",$xml,$cc_match);
    $ipDetail['country_code']=$cc_match[1]; //assing the country code to array

    //return the array containing city, country and country code
    return $ipDetail;

    }
    you can chk with this php code & you can get the DNS server ip address by giving domain name & get the ip address from ip-details.com

Similar Threads & Tags
Similar threads

  1. Chaning all IP address for one server
    By JSD in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 07-21-2008, 04:06 AM
  2. Ban IP Address from server..
    By Swampfox in forum cPanel and WHM Discussions
    Replies: 5
    Last Post: 05-12-2007, 08:45 AM
  3. setting up new IP address on server
    By agreater in forum New User Questions
    Replies: 3
    Last Post: 01-23-2006, 11:05 PM
  4. New Server IP address
    By seobeck in forum New User Questions
    Replies: 2
    Last Post: 09-05-2005, 11:53 AM
  5. Server IP Address
    By andy7t in forum Themes and Branding
    Replies: 0
    Last Post: 12-31-2003, 11:18 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube