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)?
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)?
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
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.
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>
Thanks, Matt! That worked. I was using "dedicatedip" and on some servers it wasn't returning an ip address.
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