I am not getting Output though i include all the files
<?php
/**
* Scan network to retrieve hosts and services information.
*/
require_once 'C:/xampp/php/pear/Net/Nmap.php';
//Define the target to scan
$target = array('127.0.0.1','localhost');
$options = array('nmap_binary' => 'C:/Program Files (x86)/Nmap');
try {
$nmap = new Net_Nmap($options);
//Enable nmap options
$nmap_options = array('os_detection' => true,
'service_info' => true,
'port_ranges' => 'U:53,111,137,T:21-25,80,139,8080',//to scan only specified ports
);
$nmap->enableOptions($nmap_options);
//Scan target
$res = $nmap->scan($target);
//Get failed hosts
$failed_to_resolve = $nmap->getFailedToResolveHosts();
if (count($failed_to_resolve) > 0) {
echo 'Failed to resolve given hostname/IP: ' .
implode (', ', $failed_to_resolve) .
"\n";
}
//Parse XML Output to retrieve Hosts Object
$hosts = $nmap->parseXMLOutput();
//Print results
foreach ($hosts as $key => $host) {
echo 'Hostname: ' . $host->getHostname() . "\n";
echo 'Address: ' . $host->getAddress() . "\n";
echo 'OS: ' . $host->getOS() . "\n";
echo 'Status: ' . $host->getStatus . "\n";
$services = $host->getServices();
echo 'Number of discovered services: ' . count($services) . "\n";
foreach ($services as $key => $service) {
echo "\n";
echo 'Service Name: ' . $service->name . "\n";
echo 'Port: ' . $service->port . "\n";
echo 'Protocol: ' . $service->protocol . "\n";
echo 'Product information: ' . $service->product . "\n";
echo 'Product version: ' . $service->version . "\n";
echo 'Product additional info: ' . $service->extrainfo . "\n";
}
}
} catch (Net_Nmap_Exception $ne) {
echo $ne->getMessage();
}
?>
if your program do not have any output, it means you have syntax error, fatal error or segment error.
change php.ini setting, enable, dispaly_errors, and error_reporting with E_ALL
usually, this is enough. you can see the error message and fix the bug.
if there still not error message, try create a simple file, only show phpinfo().
if this is ok, usually, you do not have start up error, if not, enable display_startup_errors in php.ini
if you still have no error, check your apache or nginx configure, you probably config the site wrong.
if you still have no error, congratulation! you got segment error.
use gdb to find the reason.
Related
This question already has answers here:
Turn off warnings and errors on PHP and MySQL
(6 answers)
Closed 5 years ago.
It prints on the screen when it is correctly entered, but I do not want to do anything when it is entered incorrectly
How can I do that?
<?php
header('Content-type: text/html; charset=utf8');
$api_key = 'local';
$keyword = 'test';
$url = 'test.json' . $api_key . '&' .'keyword' .'=' . $GLOBALS['q'] ;
$open = file_get_contents($url);
$data = json_decode($open, true);
$istatistikler = $data['data'];
if ($data) {
foreach ( $istatistikler as $istatistik ){
echo '<div class="right">';
echo 'Oyun modu: ' . $istatistik['title'] . '<br />' .
'Kazanma: ' . $istatistik['content'] . '<br />' .
'Kazanma: ' . $istatistik['image'] . '<br />' .
'Kazanma: ' . $istatistik['category'] . '<br />' .
'<br />' .
'<hr/>';
$karakter_simge = 'http://google.com' . $istatistik['image'] . '';
echo "<img src=".$karakter_simge." >" ;
echo '</div>';
}
}
?>
Successful output
Failed output
Warning:
file_get_contents(http://localhost/api/detail?X-Api-Key=local&keyword=a):
failed to open stream: HTTP request failed! HTTP/1.1 406 Not
Acceptable in /opt/lampp/htdocs/weather-master/php/php-api.php on line
10
"I do not want to print unsuccessfully"
thank you for your help!
This may be helpful:
$open = #file_get_contents($url);
# sign before a function name (in a call) prevents from showing any warnings (It's a bad practice though).
Good luck!
Change
$open = file_get_contents($url);
into
$open = #file_get_contents($url);
if ($open === false)
die("wrong");
The # suppresses the error message. Using die() will abort the script completely with the given message.
Alternatively, change the condition to !== false and wrap the rest of your "successful" code in its body:
$open = #file_get_contents($url);
if ($open !== false)
{
$data = json_decode...
...
...
}
I guess I overshot the goal here a little, but not even running into code that won't work properly without its data isn't a bad idea at all.
I'm trying the PEAR Net_Nmap package from here:
https://pear.php.net/package/Net_Nmap/
I have Nmap installed on my Windows 10 machine.
I found the following code that should do the job.
Is there something I should configure before I use PEAR?
I'm getting 2 errors:
Warning: require_once(XML/Parser.php): failed to open stream: No such file or directory in C:\xampp\htdocs\Net_Nmap-master\Net\Nmap\Parser.php on line 31
Fatal error: require_once(): Failed opening required 'XML/Parser.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\Net_Nmap-master\Net\Nmap\Parser.php on line 31
<?php
// Scan network to retrieve hosts and services information.
require_once 'Net/Nmap.php';
//Define the target and options
$target = array('193.95.13.16','www.google.com');
$options = array('nmap_binary' => 'C:\Program Files (x86)\Nmap');
try {
$nmap = new Net_Nmap($options);
$nmap_options = array(
'os_detection' => true,
'service_info' => true,
'port_ranges' => 'U:53,111,137,T:21-25,80,139,8080',
// Only specified ports
);
$nmap->enableOptions($nmap_options);
// Scan
$res = $nmap->scan($target);
// Get failed hosts
$failed_to_resolve = $nmap->getFailedToResolveHosts();
if (count($failed_to_resolve) > 0) {
echo 'Failed to resolve given hostname/IP: ' .
implode (', ', $failed_to_resolve) .
"\n";
}
//Parse XML Output to retrieve Hosts Object
$hosts = $nmap->parseXMLOutput();
//Print results
foreach ($hosts as $key => $host) {
echo 'Hostname: ' . $host->getHostname() . "\n";
echo 'Address: ' . $host->getAddress() . "\n";
echo 'OS: ' . $host->getOS() . "\n";
echo 'Status: ' . $host->getStatus . "\n";
$services = $host->getServices();
echo 'Number of discovered services: ' . count($services) . "\n";
foreach ($services as $key => $service) {
echo "\n";
echo 'Service Name: ' . $service->name . "\n";
echo 'Port: ' . $service->port . "\n";
echo 'Protocol: ' . $service->protocol . "\n";
echo 'Product information: ' . $service->product . "\n";
echo 'Product version: ' . $service->version . "\n";
echo 'Product additional info: ' . $service->extrainfo . "\n";
}
}
}
catch (Net_Nmap_Exception $ne) {
echo $ne->getMessage();
}
?>
You did not use the PEAR installer to install the net_nmap package, but probably downloaded the .tgz file and extracted it.
Now you are missing the dependencies which are listed on the bottom left of the Net_NMap page. Install them.
I'm trying this
<?php
/* read the PHP source code */
$source_code = file_get_contents("hello.php");
$source_code = preg_replace('#^<\?php\s+#', '', $source_code);
$source_code = preg_replace('#\s+\?>\s*$#', '', $source_code);
/* create the encrypted version */
$redistributable_key = blenc_encrypt($source_code, "encrypt.php", "my_fixed_password");
$key_file = __DIR__ ."\keys";
file_put_contents($key_file, $redistributable_key . "\n", FILE_APPEND);
include 'encrypt.php';
echo $hello;
?>
hello.php
<?php
$hello = "Ciao";
I got this error
PHP Fatal error: blenc_compile: Validation of script
'encrypt.php' failed, cannot execute.
Please note that:
The key file is created, I'm already using the '\n' fix
I replaced <?php and ?> because another Stack Overflow question told me that it's a problem
<?php
$file_name = basename($file);
$unencrypted_key = = md5(time());
$source_code = file_get_contents($file);
//This covers old-asp tags, php short-tags, php echo tags, and normal php tags.
$contents = preg_replace(array('/^<(\?|\%)\=?(php)?/', '/(\%|\?)>$/'), array('',''), $source_code);
$html .= "<br> BLENC blowfish unencrypted key: $unencrypted_key" . PHP_EOL;
$html .= "<br> BLENC file to encode: " . $file_name . PHP_EOL;
//file_put_contents('blencode-log', "---\nFILE: $file_name\nSIZE: ".strlen($contents)."\nMD5: ".md5($contents)."\n", FILE_APPEND);
$redistributable_key = blenc_encrypt($contents, TARGET_DIR . '/blenc/' . $file_name, $unencrypted_key);
$html .= "<br> BLENC size of content: " . strlen($contents) . PHP_EOL;
/**
* Server key
* key_file.blenc
*/
file_put_contents(TARGET_DIR . '/blenc/' . 'key_file.blenc', $redistributable_key . PHP_EOL);
$html .= "<br> BLENC redistributable key file key_file.blenc updated." . PHP_EOL;
exec("cat key_file.blenc >> /usr/local/etc/blenckeys");
?>
https://github.com/codex-corp/ncryptd/blob/master/app/controllers/MagicalController.php#L479
you should put the key to
blenckeys
file on your server
Note: Sometimes you need to reload the apache, if you have "Validation of script" issues
How to use BLENC in PHP?
I read the post here
Test if port open and forwarded using PHP
about how to scan ports of the same proxy . But my problem is I want to do scan the same port of different ip xxx.xxx.xxx.$i and for loop i try to run it from 0 to 255 . I use the same script in the above mentioned post using for loop . But it takes too long to get the answer (actually I dont get any) . Here is the code
for($i=0;$i<2;$i++){
$host = 'xxx.xxx.xxx.'.$i;
$connection = #fsockopen($host, 3128);
if (is_resource($connection))
{
echo '<h2>' . $host . ':' . $port . ' ' . '(' . getservbyport($port, 'tcp') . ') is open.</h2>' . "\n";
fclose($connection);
}
else
{
echo '<h2>' . $host . ':' . $port . ' is not responding.</h2>' . "\n";
}
}
I have a joomla page on which I want to install a few extensions. However due to the chmod permissions I am unable to upload and install the packages. Following the guide here I can see that in order for the plugins to be installed there are too many folders which permissions have to be changed.
For that I am creating a script which will iterate through each of the required folders and will change the permissions from 0775 to 0777.
<?php
// SET THE DESIRED CHMOD VALUE
if ($_GET['chmod']) {
$ftp_chmod = $_GET['chmod'];
}
else {
$ftp_chmod = "0755";
}
echo "chmod=" . $ftp_chmod . '<br />';
echo getcwd() . '<br />';
$currdir = getcwd(); // get current directory
// ESTABLISH AN FTP LOGIN SESSION
$ftp_server='example.com';
$ftp_user='username';
$ftp_pass='*****';
$conn_id = ftp_connect("$ftp_server");
if ( ftp_login($conn_id, $ftp_user, $ftp_pass) ) {
echo 'FTP CONNECTION IS SUCCESSFULL <br />';
}
else {
echo 'BAD CREDENTIALS';
exit();
}
// Define the folders for which the CHMODE will change the values
// There must be a leading space in front of the path in order for CHMOD to work
$folder_path = array(
' ' . $currdir . '/modules/',
' ' . $currdir . '/plugins/'
' ' . $currdir . '/tmp/',
' ' . $currdir . '/cache/'
);
echo '<br />';
foreach ( $folder_path as $key => $value )
{
$path = trim($value); // The leading space must be trimed fo is_dir() function to work
if ( is_dir($path) == true ) {
echo $path . ' -- ' . '<span style="color: #00B200">OK</span><br />';
echo 'CHMOD ' . $ftp_chmod . ' ' . $value . '<br />';
if (ftp_site($conn_id, 'CHMOD ' . $ftp_chmod . $value)) {
echo 'CHMOD ' . $ftp_chmod . ' IS <span style="color: #00B200">SUCCESSFULL</span><br /><br />';
}
else {
echo '<span style="color: crimson">CHMOD FAILED!</span><br /><br />';
}
}
else {
echo $path . ' -- ' . '<span style="color: crimson"><b>NOT EXIST</b></span><br />';
} // end if ( is_dir($path) == true ) else
} // end foreach ( $folder_path as $key => $value )
ftp_close($conn_id);
?>
Please note that the actual script is much larger due to the many folders that need to be changed. The folders shown in $folder_path = array() are just an example
When I execute the script on my server i get the folowind output:
chmod=0777
/var/www/example/data/www/example.com
FTP CONNECTION IS SUCCESSFULL
/var/www/example/data/www/example.com/modules/ -- OK
CHMOD 0777 /var/www/example/data/www/example.com/modules/
CHMOD FAILED!
/var/www/example/data/www/example.com/plugins/ -- OK
CHMOD 0777 /var/www/example/data/www/example.com/plugins/
CHMOD FAILED!
/var/www/example/data/www/example.com/tmp/ -- OK
CHMOD 0777 /var/www/example/data/www/example.com/tmp/
CHMOD FAILED!
/var/www/example/data/www/example.com/cache/ -- OK
CHMOD 0777 /var/www/example/data/www/example.com/cache/
CHMOD FAILED!
DOES ANYONE HAVE ANY IDEA ON HOW TO CHANGE THE CHMOD VALUE ON SO MANY FOLDERS?
UPDATE:
I also have to mention that I have tried to change the CHMOD value on each folder individually via FTP client and it is successfull. The problem comes when i have to change them through the script. The same acc with root privilege access is used from the FTP client and the script to change the files!
I have found a solution to the problem. What I did was a small modification to the foreach part of the script which made it work. Basically I just subtracted the required number of characters from the path returned from the getcwd() and that solved my problem.
Here is the change that i did:
---- REST OF THE SCRIPT OMITED -----
foreach ( $folder_path as $key => $value )
{
$path = trim($value); // The leading space must be trimed fo is_dis() function to work
if ( is_dir($path) == true ) {
$value_short = substr($value, 19); // <------------- Subtruct the required number od chars in order to create a relative path
echo $path . ' -- ' . '<span style="color: #00B200">OK</span><br />';
echo 'CHMOD ' . $ftp_chmod . ' ' . $value_short . '<br />';
if (ftp_site($conn_id, "CHMOD $ftp_chmod $value_short")) { // <-------------- Use the relative path in the function
echo 'CHMOD ' . $ftp_chmod . ' IS <span style="color: #00B200">SUCCESSFULL</span><br /><br />';
}
else {
echo '<span style="color: crimson">CHMOD FAILED!</span><br /><br />';
}
}
else {
echo $path . ' -- ' . '<span style="color: crimson"><b>NOT EXIST</b></span><br />';
} // end if ( is_dir($path) == true ) else
} // end foreach ( $folder_path as $key => $value )
---- REST OF THE SCRIPT OMITED -----
Did you try just enabling Joomla's FTP layer before installing components/plugins etc?