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.
Related
I am working on database migration. I have written a code for executing the command that retrieves the data from database and pushes into a csv file. This Works fine in MySQL but when I try to do the same in SQL Server it does not work. Infact when I copy paste the same command into command prompt it works fine. I double checked everything. I do not understand why its not working. It returns blank output. I have already tried many of the solutions provided before. None works. Any help on this is most appreciated.
Here is the code I am using:
//$sqlsrv is used to determine the database server type
$str_query = voc_get_query_string($query);
$output_uri = 'temporary://' . user_password();
$file_path = drupal_realpath($output_uri . '.csv');
if($sqlsrv){
$exec_path = drupal_realpath('private://Binn\sqlcmd');
}else{
$exec_path = drupal_realpath('private://mysql');
}
$sql_uri = 'temporary://' . user_password();
$sql_path = drupal_realpath($sql_uri);
$fp = fopen($sql_path, 'w');
fputs($fp, $str_query);
fclose($fp);
global $databases;
if ($sqlsrv) {
$cmd = ($exec_path .
' -S ' . $databases['default']['default']['host'] .
' -d ' . $databases['default']['default']['database'] .
' -U ' . $databases['default']['default']['username'] .
' -P ' . $databases['default']['default']['password'] .
' -i ' . $sql_path . '>>'. $file_path .
' -s '. '"," -W -m10 -r1');
}
else {
$cmd = ($exec_path . ' ' . $databases['default']['default']
['database'] .
' -h ' . $databases['default']['default']['host'] .
' -u ' . $databases['default']['default']['username'] .
' -p ' . $databases['default']['default']['password'] . ' < '
. $sql_path .
' > ' . $file_path);
}
exec($cmd);
watchdog('cmd', var_export($cmd, TRUE));
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.
I have a question here, tho, I've been digging here at SO, it seems I can't find the real deal;
I am trying the ff:
<?php
$filename = $trantype . $delimiter . $dateToday . $fileExtension ;
//echo $filename . '<br/>';
$fileToOpen = $filepath . $filename;
echo "File To Open: " . $fileToOpen . '<br/>';
$string = file_get_contents($fileToOpen);
//$string = file_get_contents("../transactions/o/O_20120809.xx");
$json_array = json_decode($string, true);
echo "Echo: " . $json_array[0]['itemheader_sysid'] . '<br/>';
echo "The File Contents: " . $string;
?>
The $string = file_get_contents('../transaction/o/O_20120809.xx') works smoothly on the other hand the $string = file_get_contents($fileToOpen); doesn't seem to work and is giving me the ff: error;
Warning: file_get_contents(../transactions/o/0_20120809.xx) [function.file-get-contents]: failed to open stream: No such file or directory in C:\xampp\htdocs\xx\helper\upo.php on line 19
why so?
Anyone please?
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?