&1';
exec($nc_cmd, $result, $retval);
// echo "NC CMD: {$nc_cmd}\n\n";
if (!empty($result)) {
if (is_array($result)) {
foreach ($result as $resline) {
$ncoutput .= htmlspecialchars($resline) . "\n";
}
} else {
$ncoutput .= htmlspecialchars($result);
}
}
}
}
include("head.inc");
// Handle the display of all messages here where the user can readily see them
if ($input_errors) {
print_input_errors($input_errors);
} elseif ($do_testport) {
// User asked for a port test
if ($retval == 0) {
// Good host & port
$alert_text = '
' . sprintf(gettext('Port test to host: %1$s Port: %2$s successful'), $host, $port);
if ($showtext) {
$alert_text .= ' ' . gettext('Any text received from the host will be shown below the form.');
}
} else {
// netcat exit value != 0
$alert_text = '
';
if ($showtext) {
$alert_text .= gettext('No output received, or connection failed. Try with "Show Remote Text" unchecked first.');
} else {
$alert_text .= gettext('Connection failed.');
}
}
print ($alert_text . '
');
} else {
// First time, new page
print('
' .
gettext('This page allows you to perform a simple TCP connection test to determine if a host is up and accepting connections on a given port.') . " " .
gettext('This test does not function for UDP since there is no way to reliably determine if a UDP port accepts connections in this manner.') . '
');
}
$form = new Form('Test');
$section = new Form_Section('Test Port');
$section->addInput(new Form_Input(
'host',
'Hostname',
'text',
$host,
['placeholder' => 'Hostname to look up.']
));
$section->addInput(new Form_Input(
'port',
'Port',
'text',
$port,
['placeholder' => 'Port to test.']
));
$section->addInput(new Form_Input(
'srcport',
'Source Port',
'text',
$srcport,
['placeholder' => 'Typically left blank.']
));
$section->addInput(new Form_Checkbox(
'showtext',
'Remote text',
'Show remote text',
$showtext
))->setHelp("Shows the text given by the server when connecting to the port. If checked it will take 10+ seconds to display in a panel below this form.");
$section->addInput(new Form_Select(
'sourceip',
'Source Address',
$sourceip,
['' => 'Any'] + get_possible_traffic_source_addresses(true)
))->setHelp('Select source address for the trace');
$section->addInput(new Form_Select(
'ipprotocol',
'IP Protocol',
$ipprotocol,
array('ipv4' => 'IPv4', 'ipv6' => 'IPv6')
))->setHelp("If you force IPv4 or IPv6 and use a hostname that does not contain a result using that protocol, it will result in an error." .
" For example if you force IPv4 and use a hostname that only returns an AAAA IPv6 IP address, it will not work.");
$form->add($section);
print $form;
// If the command succeeded, the user asked to see the output and there is output, then show it.
if ($retval == 0 && $showtext && !empty($ncoutput)):
?>
=gettext('Received Remote Text')?>