Annunci
RSS

Archivio dell'autore: peterwadid

shell commands on SSH enabled System using JSch library

package com.corejsf.java;

import java.io.BufferedReader;
import java.io.Console;
import java.io.InputStream;

import java.io.InputStreamReader;

import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;

public class SSHCommandExecutor {

/**
* @param args
*/
public static void main(String[] args) {
String host = “”;
String user = “”;
String password = “”;
String command1 = “”;
Channel channel = null;

// open up standard input
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

try {

java.util.Properties config = new java.util.Properties();
config.put(“StrictHostKeyChecking”, “no”);
JSch jsch = new JSch();
System.out.print(“Host : “);
host = br.readLine();
System.out.print(“UserName : “);
user = br.readLine();
System.out.print(“Password : “);
password = br.readLine();
System.out.print(“Command : “);
command1 = br.readLine();
Session session = jsch.getSession(user, host, 22);
session.setPassword(new String(password));
session.setConfig(config);
session.connect();
System.out.println(“Connected”);

channel = session.openChannel(“exec”);
((ChannelExec) channel).setCommand(command1);
channel.setInputStream(null);
((ChannelExec) channel).setErrStream(System.err);

InputStream in = channel.getInputStream();
channel.connect();
byte[] tmp = new byte[1024];
while (true) {
while (in.available() > 0) {
int i = in.read(tmp, 0, 1024);
if (i < 0)
break;
System.out.print(new String(tmp, 0, i));

}
if (channel.isClosed()) {
System.out.println("exit-status: "
+ channel.getExitStatus());
break;
}
try {
Thread.sleep(1000);
} catch (Exception ee) {
}
}

channel.disconnect();
session.disconnect();
System.out.println("DONE");
} catch (Exception e) {
e.printStackTrace();
}

}

}

Annunci
 
Lascia un commento

Pubblicato da su gennaio 9, 2015 in Linux

 
Link

للتحميل إضعط علي اللينك :

مسابقه الصوم الكبير الأحد الخامس 

 
Lascia un commento

Pubblicato da su aprile 7, 2013 in Uncategorized

 

Get User’s Remote IP Address using PHP

A Function in PHP to get user’s remote IP Address

<?php

function getRemoteIP ()
{

// check to see whether the user is behind a proxy – if so,
// we need to use the HTTP_X_FORWARDED_FOR address (assuming it’s available)

if (strlen($_SERVER[“HTTP_X_FORWARDED_FOR”]) > 0) {

// this address has been provided, so we should probably use it

$f = $_SERVER[“HTTP_X_FORWARDED_FOR”];
$reserved = false;

// check reserved range 10.0.0.0 – 10.255.255.255
if (substr($f, 0, 3) == “10.”) {
$reserved = true;
}

// check reserved range 172.16.0.0 – 172.31.255.255
if (substr($f, 0, 4) == “172.” && substr($f, 4, 2) > 15 && substr($f, 4, 2) < 32) {
$reserved = true;
}

// check reserved range 192.168.0.0 – 192.168.255.255
if (substr($f, 0, 8) == “192.168.”) {
$reserved = true;
}

// now we know whether this address is any use or not
if (!$reserved) {
$ip = $f;
}

}

// if we didn’t successfully get an IP address from the above, we’ll have to use
// the one supplied in REMOTE_ADDR

if (!isset($ip)) {
$ip = $_SERVER[“REMOTE_ADDR”];
}

// done!
return $ip;

}

echo “Your ip address”.getRemoteIP();

?>

 
Lascia un commento

Pubblicato da su aprile 3, 2013 in Programming

 

Tag: , , ,

Using SSMTP Mail Client With PHP

After installing the SSMTP (Linux Mail Client)

http://peterwadid.com/2013/03/26/linux-ssmtp-mail-client-configuration/

Now We are going to use it with PHP, Just Create a file (mailTest.php)

mailTestPhp

Then ,

MailSend

 

Finally , Test your PHP Script from the Command Line

CallPHPScript

 
Lascia un commento

Pubblicato da su marzo 27, 2013 in Linux

 

Linux SSMTP Mail Client Configuration


ssmtpConf

Add these lines to the ssmtp configuration file (ssmtp.conf)

ssmtpConf2

 

 

 
2 commenti

Pubblicato da su marzo 26, 2013 in Uncategorized