Get remote host php

Get remote host status information and details using PHP

Question: I would like to create script that will monitor resources(CPU,RAM,DISK) on remote linux servers (client servers). It supports mounting remote servers a local netdrive in Windows via FTP, SSH or SFTP .

Get remote host status information and details using PHP

I’m looking to get server details from a remote server using PHP. I know I can get some details by just grabbing the headers, but I also want to get the server up time, bandwidth usage, etc. If you could tell me how to do this or point me in the right direction, I would be appreciative.

http://phpsysinfo.sourceforge.net/ or http://www.zabbix.com/

Zabbix is professional yet opensource network monitoring system and works excellent and could provide you all info you’re looking for. It’s frontend is written completely in PHP so you can hack into it the way you want.

Basically you can’t get all the information that you’re looking for without installing some program or tools on server which can monitor these parameters for you and return you back. May be you can get » uptime » by executing command using exe( uptime ) or something similar but for bandwidth usage I think it would be difficult to get unless you get it by firing some commands in background in your php script. Some of the utilities which might help you do that would be ifstat or iftop but they are not installed by default on ubuntu/debian based systems so if you want to use them you need to install them so not possible w/o access to machine.

Читайте также:  Степенной метод нахождения собственных значений python

PHP IDE for Search in remote file without store the files to local

Are there any good IDEs which can search for a word or phrase from the remote files without storing/synchroning to my local computer first?

I have tried Aptana, but it doesn’t seem to be able to do this but, the remote file system is good(not store to local)

I have tried Netbeans, which seems to alway store files to my local machine first.

I hoping that there are (preferably free) IDEs out there that can run searches for strings on the my remote host?

I see three possible (common) options:

  • Connect via ssh and use vim . I would do that.
  • Mount the remote file system via scp (sshfs on Linux) or ftp (curlftpfs on Linux). This will hide file transmission from you but they will be done it background. So it’s much the same as let the IDE do the ftp work
  • Have the IDE (whatever you prefer) running on the remote host and using RemoteDesktop or somewhat else.

Using ssh may be the most secure and usual approach. The less data intensive will be using FTP with Aptana as you already doing (Expecting that Aptana just transmitts changed files). (Also this may depend on the filesize and circumstances but with usual code files I would say so)

If you are working on Windows expandrive might be an approach. It supports mounting remote servers a local netdrive in Windows via FTP, SSH or SFTP . An IDE would see that folder like a local folder. You should give it a try.

Update: Trying to explain more.

If you want to search in a remote file, you have two general options:

  • The search program runs locally and will need input data from remote (the file)
  • The serach program runs remotely. You’ll send arguments to it, and it will send back the search results

In IDE speaks it means: Either you use the search functionality of your IDE itself, means the search program (IDE) runs locally, then the file has to be downloaded / sychnronized / netmounted whatever. Or you execute grep or whatever remotely and display the results. Then it mostly comes to ssh. Your IDE will need a ssh plugin for that. Eclipse for example has one. (Think to remember the name was RSE. Remote Systems Explorer) (It will work with Aptana too) .

Php script to access remote linux server and execute bash script, I am trying to do the following. Have php execute shell commands on our remote servers. This because i

How to programatically monitor resources (CPU, RAM,DISK) of remote linux server?

I would like to create script that will monitor resources(CPU,RAM,DISK) on remote linux servers (client servers). What would be the best way to access these parameters remotely ?

I would prefer something based on PHP. I don’t need ready-to-use solution, I need to create it myself as I need possibility for customization.

Client side script/program must be easy to configure/install.

I wrote a Java application called the remote-linux-monitor. You can find the source at https://github.com/dbothwell/remote-linux-monitor . If you study the code you will find techniques for calculating cpu and memory load. I hope you find it helpful.

Since you say you just need pointers, you’ll need to parse /proc/cpuinfo , /proc/meminfo and /proc/diskstats . These contain real time data exported by the kernel.

Hey sorry for late reply. I have written this program in PHP that will show you the CPU and RAM usage stats of your server.

You can check it out here — http://code.google.com/p/php-cpu-monitor/

I know you said you’re not really looking for a completed solution but it is quite simple and I’ve documented it all so it would be easy to modify.

How to run remote SSH commands non-interactively via Bash or, My last bet would be an exec() call in PHP to simply run the ssh command, i just couldn’t find a way to supply the default password. (key

CodeIgniter project not work on Linux-based remote server

I developed a project with CodeIgniter on windows XAMPP which works. But does not work on Linux-based remote server.

I get the error:

Controller: home.php:

public function index()< $this->load->view('home'); > 
RewriteEngine on RewriteCond $1 !^(index\\.php|resources|robots\\.txt) RewriteCond % !-f RewriteCond % !-d RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

On codeIgniter 3 + versions a couple of checks to do if getting errors below.

  • Make sure your file name has the first letter upper case only
  • Make sure your class name has first letter upper case only
  • This applies for models as well.

Warning: Some times even though lower case may work on some localhost some other operating systems it may cause error when file or class are lower case, it may not be the same for everyone.

File name: Home.php

load->model('model_example'); > public function index()< // $data['results'] = $this->model_example->get_results(); $this->load->view('home'); > > 

Folder Structure for View

application application > views > home.php 

File name: Model_example.php

$config['base_url'] = 'http://localhost/your_project_name/'; 

Rather than uploading the codeigniter site directly you should be able to use something like Putty (http://www.putty.org/) to install a fresh version of Codeigniter through script and then add the files for your site to the installation.

The script used to install a fresh version of CI will differ based on what Linux platform you’re using. wget is used for ubuntu.

Checking a remote host (Linux) hard disk space, Alternatively you can setup some monitor service in the remote server, and use some convenient webpages or api to get the information. but that

Источник

gethostbyaddr

Returns the host name of the Internet host specified by ip .

Parameters

Return Values

Returns the host name on success, the unmodified ip on failure, or false on malformed input.

Examples

Example #1 A simple gethostbyaddr() example

$hostname = gethostbyaddr ( $_SERVER [ ‘REMOTE_ADDR’ ]);

See Also

  • gethostbyname() — Get the IPv4 address corresponding to a given Internet host name
  • gethostbynamel() — Get a list of IPv4 addresses corresponding to a given Internet host name

User Contributed Notes 35 notes

Sometimes when using $_SERVER[‘HTTP_X_FORWARDED_FOR’] OR $_SERVER[‘REMOTE_ADDR’] more than 1 IP address is returned, for example ‘155.240.132.261, 196.250.25.120’. When this string is passed as an argument for gethostbyaddr() PHP gives the following error: Warning: Address is not a valid IPv4 or IPv6 address in.

To work around this I use the following code to extract the first IP address from the string and discard the rest. (If you wish to use the other IPs they will be in the other elements of the $ips array).

if (strstr($remoteIP, ‘, ‘)) $ips = explode(‘, ‘, $remoteIP);
$remoteIP = $ips[0];
>

The problem of broken DNS servers was causing me a problem because i had a page for user statistics that required around 20 reverse dns lookups to be done, and even as many as 5/6 of them being broken was causing a huge delay in loading the page. so i wrote a function that uses a UDP socket to talk directly to the DNS server (instead of going via the normal gethostbyaddr function) this let me set a timeout.

The only requirement is that your DNS server must be able to do recursive lookups, it wont go to other DNS servers if its told to. and of course you need to know your DNS servers IP address 🙂

function gethostbyaddr_timeout($ip, $dns, $timeout=1000)
// random transaction number (for routers etc to get the reply back)
$data = rand(0, 99);
// trim it to 2 bytes
$data = substr($data, 0, 2);
// request header
$data .= «\1\0\0\1\0\0\0\0\0\0»;
// split IP up
$bits = explode(«.», $ip);
// error checking
if (count($bits) != 4) return «ERROR»;
// there is probably a better way to do this bit.
// loop through each segment
for ($x=3; $x>=0; $x—)
// needs a byte to indicate the length of each segment of the request
switch (strlen($bits[$x]))
case 1: // 1 byte long segment
$data .= «\1»; break;
case 2: // 2 byte long segment
$data .= «\2»; break;
case 3: // 3 byte long segment
$data .= «\3»; break;
default: // segment is too big, invalid IP
return «INVALID»;
>
// and the segment itself
$data .= $bits[$x];
>
// and the final bit of the request
$data .= «\7in-addr\4arpa\0\0\x0C\0\1»;
// create UDP socket
$handle = @fsockopen(«udp://$dns», 53);
// send our request (and store request size so we can cheat later)
$requestsize=@fwrite($handle, $data);

@socket_set_timeout($handle, $timeout — $timeout%1000, $timeout%1000);
// hope we get a reply
$response = @fread($handle, 1000);
@fclose($handle);
if ($response == «»)
return $ip;
// find the response type
$type = @unpack(«s», substr($response, $requestsize+2));
if ($type[1] == 0x0C00) // answer
// set up our variables
$host=»»;
$len = 0;
// set our pointer at the beginning of the hostname
// uses the request size from earlier rather than work it out
$position=$requestsize+12;
// reconstruct hostname
do
// get segment size
$len = unpack(«c», substr($response, $position));
// null terminated string, so length 0 = finished
if ($len[1] == 0)
// return the hostname, without the trailing .
return substr($host, 0, strlen($host) -1);
// add segment to our host
$host .= substr($response, $position+1, $len[1]) . «.»;
// move pointer on to the next segment
$position += $len[1] + 1;
>
while ($len != 0);
// error — return the hostname we constructed (without the . on the end)
return $ip;
>
return $ip;
>
?>

This could be expanded quite a bit and improved but it works and i’ve seen quite a few people trying various methods to achieve something like this so i decided to post it here. on most servers it should also be more efficient than other methods such as calling nslookup because it doesn’t need to run external programs

Note: I’m more a C person than a PHP person, so just ignore it if anything hasn’t been done the *recomended* way 🙂

Источник

Оцените статью