本文整理汇总了PHP中Net_SSH2类的典型用法代码示例。如果您正苦于以下问题:PHP Net_SSH2类的具体用法?PHP Net_SSH2怎么用?PHP Net_SSH2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Net_SSH2类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: Exec
public function Exec($command)
{
$engine = $this->session->getSpooler();
if (!isset($engine[0]['shell'])) {
print "?!";
exit;
}
$shell = $engine[0]['shell'];
$host = $shell['host'];
$user = $shell['user'];
$password = $shell['password'];
$method = 'CURL';
set_include_path(get_include_path() . PATH_SEPARATOR . '../vendor/phpseclib');
include 'Net/SSH2.php';
include 'Crypt/RSA.php';
$ssh = new \Net_SSH2($host);
if (1) {
$key = new \Crypt_RSA();
$ret = $key->loadKey("-----BEGIN RSA PRIVATE KEY-----\nMIICWgIBAAKBgQCzRy01HoHIzBJJb/D8A/eTV3qiZxy0NIR97NE14rJblnJZT5Kg\noP2DvIRzlB0msL5cHQJ/qXYAoemHRDKqNZuj89+MYsBeZqNu3/DXdZLq9XJ8e2rb\nsGrDjHvCHEDWL0JIRFnRacem55+XsUsKTIs4tbcD6adMPIYJSQQ7oB/8AQIBIwKB\ngB67vptkUMNWLwVGY9NuZPSv6SMnnoVK1OJjHIzlCKH8iKGYnMsUSLd/ZynBnpjr\nGVGekrbMl+LZ7YTnHqDV/WxGoWEc3xiHE8/HwZwQZxP92K70inz8+6dGEagsrSqO\nQkdAPR/+qen7uQ9yXqj7WAoNFicPJ2cpo8kuEW33KywzAkEA4yH4jf0uNBFDUkR6\ni9DQC5bsgEloVezWnCsm6eIm5o5SGKPZ6Rpro/h3pq5qvPmCtjrZFnK0Dab9xkFr\n/F9lkwJBAMoQMqxYdnPz74Bto99o0PZrk2ikROwXR9eURi3B4bWGq9+mvN3OEQdE\n8JofGyq60LMlnFAkE7v49fYHziyaFJsCQHTPpGZHsVybKe/LcjlG0WULyhYXH7cp\nWG2SiQqRkFlQgf4LH5xz/Nf8IEcX3x9bv5DrEI8zrQ5V4Zko9bT93HcCQQCEyNDX\np9jP2tCWOWuwEa3jwwkY4PoXfQNTJuxJ9G/AbnDyDnwcup15zje1vKtz2dmaS+pg\njLyC1s2Ea4d8ZUC9AkAeUr/N+011K2zGTjxZnAFY/Ow348bomzddiJYAYA+76exV\n3wUYsjeDxqq8Km93+iMQ8DDNZIvoVcfYQW9BfDlf\n-----END RSA PRIVATE KEY----- ");
if (!$ret) {
echo "loadKey failed\n";
print "<pre>" . $ssh->getLog() . '</pre>';
exit;
}
} elseif (isset($shell['password'])) {
$key = $shell['password'];
} else {
$key = '';
// ?! possible ?
}
if (!$ssh->login($user, $key)) {
exit("Login Failed ({$user})");
}
return $ssh->exec("system '{$command}'");
}
开发者ID:AriiPortal,项目名称:I5Bundle,代码行数:35,代码来源:AriiExec.php
示例2: getSSH
/**
* Logs in to a SSH server with the specified credentials,
* and returns the Net_SSH2 instance.
*
* @return Net_SSH2 $ssh
* @author Ronald Rey
**/
public static final function getSSH($host, $user, $pass, $timeout)
{
$ssh = new Net_SSH2($host);
if (!$ssh->login($user, $pass)) {
exit('Login to failed.');
}
$ssh->setTimeout($timeout);
$ssh->write(" ");
return $ssh;
}
开发者ID:reyronald,项目名称:CiscoSSH,代码行数:17,代码来源:CiscoSSH.php
示例3: Exec
public function Exec($shell, $command, $stdin = '')
{
$host = $shell['host'];
$user = $shell['user'];
$ssh = new \Net_SSH2($host);
if (isset($shell['key'])) {
$key = new \Crypt_RSA();
$ret = $key->loadKey($shell['key']);
if (!$ret) {
$this->status = '!KEY';
echo "loadKey failed\n";
print "<pre>" . $ssh->getLog() . '</pre>';
return;
}
} elseif (isset($shell['password'])) {
$key = $shell['password'];
} else {
$key = '';
// ?! possible ?
}
if (!@$ssh->login($shell['user'], $key)) {
$this->status = '!LOGIN';
print 'Login Failed: ' . $shell['user'];
print "<pre>" . $ssh->getLog() . '</pre>';
return;
}
$this->status = 'RUNNING';
if ($stdin == '') {
return $ssh->exec("{$command}");
}
return;
}
开发者ID:AxelANGENAULT,项目名称:CoreBundle,代码行数:32,代码来源:AriiExec.php
示例4: getPing
function getPing($sourceIP, $destinationIP)
{
// This will work with any pfSense install. $sourceIP is the IP address of the WAN that you want to
// use to ping with. This allows you to ping the same address from multiple WANs if you need to.
global $local_pfsense_ip;
global $pfSense_username;
global $pfSense_password;
$ssh = new Net_SSH2($local_pfsense_ip);
if (!$ssh->login($pfSense_username, $pfSense_password)) {
//exit('Login Failed');
return array(0, 0);
}
$terminal_output = $ssh->exec('ping -c 5 -q -S ' . $sourceIP . ' ' . $destinationIP);
// If using something besides OS X you might want to customize the following variables for proper output of average ping.
$findme_start = '= ';
$start = strpos($terminal_output, $findme_start);
$ping_return_value_str = substr($terminal_output, $start + 2, 100);
$findme_stop1 = '.';
$stop = strpos($ping_return_value_str, $findme_stop1);
$findme_avgPing_decimal = '.';
$avgPing_decimal = strpos($ping_return_value_str, $findme_avgPing_decimal, 6);
$findme_forward_slash = '/';
$avgPing_forward_slash = strpos($ping_return_value_str, $findme_forward_slash);
$avgPing = substr($ping_return_value_str, $stop + 5, $avgPing_decimal - $avgPing_forward_slash - 1);
return $avgPing;
}
开发者ID:maaximal,项目名称:Network-Status-Page,代码行数:26,代码来源:SABthrottle.php
示例5: Exec
public function Exec($host, $user, $password, $command)
{
$ssh = new Net_SSH2($host);
if (!$ssh->login($user, $password)) {
exit('Login Failed');
}
echo $ssh->exec("system '{$command}'");
}
开发者ID:AxelANGENAULT,项目名称:CoreBundle,代码行数:8,代码来源:AriiSSH.php
示例6: delete_user
function delete_user($username, $server_host, $server_username, $server_password)
{
$ssh = new Net_SSH2($server_host);
if ($ssh->login($server_username, $server_password) == false) {
exit('Login Failed');
}
$command = 'userdel -r ' . $username;
echo $ssh->exec($command);
}
开发者ID:istrwei,项目名称:vpn_manager,代码行数:9,代码来源:lib.php
示例7: ConectSSHStation
function ConectSSHStation($server)
{
$ssh = new Net_SSH2($server);
if (!$ssh->login(userubnt, passubnt)) {
print "Login Failed {$server}";
}
$mca = $ssh->exec("mca-status");
return $mca;
}
开发者ID:procamora,项目名称:Scripts-PHP,代码行数:9,代码来源:MonitorizaAntenas.php
示例8: Exec
public function Exec($command)
{
set_include_path(get_include_path() . PATH_SEPARATOR . '../vendor/phpseclib');
include 'Net/SSH2.php';
$ssh = new \Net_SSH2($this->host);
if (!$ssh->login($this->user, $this->password)) {
exit('Login Failed');
}
return $ssh->exec("system '{$command}'");
}
开发者ID:AriiPortal,项目名称:Arii,代码行数:10,代码来源:AriiExec.php
示例9: connectToServer
public function connectToServer()
{
include Mage::getBaseDir('base') . DS . 'lib' . DS . 'Ssh' . DS . 'Net' . DS . 'SSH2.php';
$ssh = new Net_SSH2($this->getMacServerIp());
if ($ssh->login($this->getMacServerUser(), $this->getMacServerPassword())) {
return $ssh;
} else {
return false;
}
}
开发者ID:Thinlt,项目名称:simicart,代码行数:10,代码来源:Ssh.php
示例10: runcmd
function runcmd($cmd)
{
include 'Net/SSH2.php';
$ssh = new Net_SSH2('localhost');
if (!$ssh->login('rc', 'cacapedo')) {
exit('Login Failed');
}
// echo $ssh->exec('pwd');
$r = $ssh->exec($cmd);
return str_replace("\n", "<br>", $r);
}
开发者ID:raulastu,项目名称:sshmail,代码行数:11,代码来源:runbash.php
示例11: connect
/**
* connect to the remote server
* @return bool|\Net_SSH2
*/
private function connect()
{
$ssh = new \Net_SSH2(Setting::getSetting('remote:host'));
$key = new Crypt_RSA();
$key->loadKey(file_get_contents(Setting::getSetting('ssh:priv_key')));
if (!$ssh->login(Setting::getSetting('remote:user'), $key)) {
$cli = new CLImate();
$cli->error("Could not connect to server");
return false;
}
return $ssh;
}
开发者ID:VonUniGE,项目名称:consh,代码行数:16,代码来源:SSHConnection.php
示例12: localhost_connect
public static function localhost_connect()
{
global $cphp_config;
$sSSH = new Net_SSH2('127.0.0.1');
$sKey = new Crypt_RSA();
$sKey->loadKey(file_get_contents($cphp_config->settings->rootkey));
if ($sSSH->login("root", $sKey)) {
return $sSSH;
} else {
return $sErrors = array("Could not connect to the local host.");
}
}
开发者ID:AstroProfundis,项目名称:Feathur,代码行数:12,代码来源:vps.class.php
示例13: newNetSSH2
/**
* Establish a SSH2 connection using PHPSECLIB
*
* @return object (ssh obj) OR string (err)
*/
function newNetSSH2($ip, $sshport = 22, $login, $password)
{
$ssh = new Net_SSH2($ip, $sshport);
if (!$ssh->login($login, $password)) {
$socket = @fsockopen($ip, $sshport, $errno, $errstr, 5);
if ($socket == FALSE) {
$debug = "Unable to connect to {$ip} on port {$sshport} : {$errstr} ( Errno: {$errno} )";
return $debug;
}
return 'Unable to connect to box with SSH';
}
return $ssh;
}
开发者ID:404rq,项目名称:bgpanel,代码行数:18,代码来源:func.ssh2.inc.php
示例14: connect_to_ssh
/** IS USED TO CONNECT TO SSH
INCLUDE THIS BEFORE FUNCTION CALL
* set_include_path(get_include_path() . PATH_SEPARATOR . ROOT_DIRECTORY_PATH . 'phpseclib');
include_once('Net/SSH2.php');
include_once('Crypt/RSA.php');
EXAMPLE AT addEc2Request.php
@return empty sting if thigs goes wrong.
*/
function connect_to_ssh($publicDnsName, $keyPairName)
{
$ssh = new Net_SSH2($publicDnsName);
$key = new Crypt_RSA();
$key->loadKey(file_get_contents(ROOT_DIRECTORY_PATH . AMAZON_SSH_KEYS . $keyPairName));
if (!$ssh->login('ubuntu', $key)) {
//WHEN USER IS NOT LOGGED INTO SSH
return 2;
} else {
//if things goes right.
return array('Net_SSH2' => $ssh, 'Crypt_RSA' => $key);
}
}
开发者ID:myvirtualteams,项目名称:samplecode,代码行数:22,代码来源:amazon.php
示例15: execute
/**
* Execute task and return report info
*
* @return \Deployer\Task
*/
public function execute()
{
foreach ($this->params() as $param => $value) {
$this->_params[$param] = \Deployer::applyGlobalParams($value);
}
$ssh = new \Net_SSH2($this->param('host'), $this->param('port'));
if (!$ssh->login($this->param('username'), $this->param('password'))) {
throw new \Deployer\TaskException('Can\'t connect to remote host');
}
$scp = new \Net_SCP($ssh);
$scp->put($this->param('dest'), file_get_contents($this->param('file')));
$info = sprintf('Filesize: %d bytes', filesize($this->param('file')));
return $this->info($info);
}
开发者ID:Leemo,项目名称:deployer,代码行数:19,代码来源:Sftp.php
示例16: set_addr
function set_addr($subnet, $interface)
{
$interface = $interface != '' ? $interface : $GLOBALS['ethernet_forenaming_scheme'] . '1';
$ip = explode('/', $subnet);
$cidr = $ip[1];
$ip_parts = explode('.', $ip[0]);
$ip_parts[3] = $ip_parts[3] + 1;
$gw = implode('.', $ip_parts);
$ip_parts[3] = $ip_parts[3] + 1;
$ip = implode('.', $ip_parts);
$ssh = new Net_SSH2('192.168.88.1');
if ($ssh->login('admin', $GLOBALS['admin_password'])) {
//while we're here we might as well reset the mac addresses again.
$detail = $ssh->exec('int eth print');
if (preg_match_all("/{$GLOBALS['ethernet_forenaming_scheme']}/", $detail, $matches)) {
$i = 1;
foreach ($matches[0] as $match) {
$ssh->exec('int ethernet reset-mac-address ' . $GLOBALS['ethernet_forenaming_scheme'] . $i);
$ssh->exec(':beep frequency=120 length=2ms;');
$i++;
if ($i == '10') {
$ssh->exec('int ethernet reset-mac-address ' . $GLOBALS['sfp_forenaming_scheme'] . '1');
}
}
}
$ssh->exec('ip address add address=' . $ip . '/' . $cidr . ' interface=' . $interface);
//set the ip on the specified interface.
$ssh->exec('ip route add dst-address=0.0.0.0/0 gateway=' . $gw);
//add the default route
}
}
开发者ID:jamenlang,项目名称:mikrotik-php,代码行数:31,代码来源:fast_config.php
示例17: connect
function connect()
{
try {
$ssh = new \Net_SSH2($this['addr'], $this['ssh_port'] ?: 22);
$key = $this->getPrivateKey();
if (!$ssh->login($this['ssh_user'] ?: 'dokku', $key)) {
throw $this->exception('Login Failed!');
}
return $ssh;
} catch (BaseException $e) {
throw $e;
// don't do anything yet
// var_dump($e);
}
}
开发者ID:romaninsh,项目名称:dokku_alt,代码行数:15,代码来源:Host.php
示例18: runCommand
public function runCommand($cmd)
{
if (!empty($this->key_path)) {
$key = new Crypt_RSA();
$key->loadKey(file_get_contents($this->key_path));
}
$ssh = new Net_SSH2($this->host, $this->port);
if ($key) {
$ssh->login($this->user, $key);
} else {
$ssh->login($this->user, $this->password);
}
$out = $ssh->exec($cmd);
return $out;
}
开发者ID:rafeco,项目名称:simpledeployer,代码行数:15,代码来源:SshHelper.php
示例19: server_connect
public static function server_connect($sServer, $sAPI = 0)
{
$sSSH = new Net_SSH2($sServer->sIPAddress);
if ($sServer->sPassword == 0) {
$sKey = new Crypt_RSA();
$sKey->loadKey(file_get_contents('/var/feathur/data/keys/' . $sServer->sKey));
} else {
$sKey = file_get_contents('/var/feathur/data/keys' . $sServer->sKey);
}
try {
if (!$sSSH->login($sServer->sUser, $sKey)) {
if (!empty($sAPI)) {
return $sResult = array("result" => 'Unable to connect to the host node, please contact customer service.');
}
echo json_encode(array("result" => 'Unable to connect to the host node, please contact customer service.'));
die;
} else {
$sSSH->setTimeout(30);
return $sSSH;
}
} catch (Exception $e) {
if (!empty($sAPI)) {
return $sResult = array("result" => 'Unable to connect to the host node, please contact customer service.');
}
echo json_encode(array("result" => 'Unable to connect to the host node, please contact customer service.'));
die;
}
}
开发者ID:AstroProfundis,项目名称:Feathur,代码行数:28,代码来源:servers.class.php
示例20: setUp
protected function setUp()
{
if (!file_exists('config.php')) {
$this->markTestSkipped("Can't run test without setting up a local configution! See config.dist.php");
}
include 'config.php';
include_once 'Net/SSH2.php';
$this->client = Net_SSH2::factory('LibSSH2', $options['libssh2']);
}
开发者ID:pear,项目名称:net_ssh2,代码行数:9,代码来源:LibSSH2Test.php
注:本文中的Net_SSH2类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论