PHP/Development/System Command
Содержание
- 1 Calling the man Command
- 2 Execute help command and check its output
- 3 Execute shell command "dir"
- 4 Ping command
- 5 Ping server
- 6 Porter scanner
- 7 Using exec() to Produce a Directory Listing
- 8 Using popen() to Pass Data to the column Application
- 9 Using popen() to Read the Output of the UNIX who Command
- 10 Administrators currently logged on to the server</h1> <?php $ph = popen( "who", "r" ) or die( "Couldn"t open connection to "who" command" ); $host="www.wbex.ru"; while ( ! feof( $ph ) ){ $line = fgets( $ph, 1024 ); if ( strlen( $line ) <= 1 ) continue; $line = ereg_replace("^([a-zA-Z0-9_\-]+).*", "<a href=\"mailto:\\1@$host\">\\1</a>\n",$line ); print "$line"; } pclose( $ph ); ?> </table> </body> </html> </source>
Calling the man Command
<source lang="html4strict">
<html> <head> <title>Calling the man command.</title> </head> <body> <form>
<input type="text" value="<?php print $manpage; ?>" name="manpage">
</form>
<?php if ( isset($manpage) ) system( "man $manpage | col -b" ); ?>
</table> </body> </html>
</source>
Execute help command and check its output
<source lang="html4strict">
<?php $command = "help"; $logged_in = explode(" ", shell_exec($command)); for ($i = 0; $i < count($logged_in); $i++) {
if ($argv[1] == trim($logged_in[$i])) { $found_user = 1; }
} if($found_user) {
print "User $argv[1] is currently logged in\n";
} else {
print "User $argv[1] is NOT currently logged in\n";
} ?>
</source>
Execute shell command "dir"
<source lang="html4strict">
<?php $dir = shell_exec("dir"); $subject = "Half-hourly file report."; $body = "The following files are in the current directory : \n\n"; $body .= $dir; echo $body; ?>
</source>
Ping command
<source lang="html4strict">
<?
$command = "ping -c5 www.thickbook.ru";
exec($command, $result, $rval);
for ($i = 0; $i < sizeof($result); $i++) {
echo "$result[$i]
";
}
?>
</source>
Ping server
<source lang="html4strict">
<?php
$server = "www.wbex.ru"; $count = 3;echo "
"; system("/bin/ping -c $count $server"); echo "";
system("killall -q ping");
?>
</source>
Porter scanner
<source lang="html4strict">
<?php
$target = "www.wbex.ru";echo "
"; system("/usr/bin/nmap $target"); echo "";
// Kill the task system("killall -q nmap");
?>
</source>
Using exec() to Produce a Directory Listing
<source lang="html4strict">
<html> <head> <title>Using exec() to produce a directory listing</title> </head> <body> <?php exec( "ls -al .", $output, $return );
print "Returned: $return
";foreach ( $output as $file )
print "$file
";
?> </table> </body> </html>
</source>
Using popen() to Pass Data to the column Application
<source lang="html4strict">
<html> <head> <title>Using popen() to pass data to the column command</title> </head> <body> <?php $products = array(array( "A", 2, "red" ),
array( "B", 3, "blue" ), array( "C", 1, "pink" ), array( "D", 1, "orange" )
); $ph = popen( "column -tc 3 -s / > data.txt", "w" ) or die( "Couldn"t open connection to "column" command" ); foreach ( $products as $prod )
fputs( $ph, join("/", $prod)."\n");
pclose( $ph ); ?> </table> </body> </html>
</source>
Using popen() to Read the Output of the UNIX who Command
<source lang="html4strict">
<html>
<head>
<title>Using popen() to read the output of the UNIX who command</title>
</head>
<body>