Acá va mi screenshot:

Saludos!
WhiZ

Saludos!
WhiZ

Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menú
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
Y el siguiente numero de este taller??




netstat -banonetstat -pale/* Server */
import java.net.*;
import java.io.*;
class Server {
public static void main(String[] args) {
System.out.println(" [*] Running server...");
ServerSocket server;
int port = 2236;
try {
server = new ServerSocket(port);
System.out.println(" [+] OK");
System.out.println(" [*] Waiting for clients on port " + server.getLocalPort());
while (true) {
Socket sock = server.accept();
Thread t = new ThreadServerHandler(sock);
t.start();
}
} catch(SocketTimeoutException e) {
System.out.println(" [!] Error: " + e);
} catch (IOException e) {
System.out.println(" [!] Error: " + e);
}
}
}
class ThreadServerHandler extends Thread {
private Socket sock = null;
public ThreadServerHandler(Socket sock) {
super("ThreadServerHandler");
this.sock = sock;
}
public void run() {
try {
System.out.println("\n [+] New client: " + sock.getRemoteSocketAddress());
while (true) {
// Receiving data
DataInputStream input = new DataInputStream(sock.getInputStream());
String data = input.readUTF();
System.out.println("\n [*] Receiving data..." + data);
System.out.println(" [+] OK");
// Sending data
DataOutputStream output = new DataOutputStream(sock.getOutputStream());
System.out.println(" [*] Sending data..." + data);
output.writeUTF(data);
System.out.println(" [+] OK");
// Exit
if (data.equals("exit")) {
System.out.println("\n [*] Closing connection to host " + sock.getRemoteSocketAddress());
sock.close();
break;
}
}
}
catch (IOException e) {
System.out.println(" [!] Error: the connection with host " +
sock.getRemoteSocketAddress() + " has been lost");
}
}
}/* Client */
import java.net.*;
import java.io.*;
import java.util.Scanner;
class Client {
public static void main(String[] args) {
String server = "127.0.0.1";
int port = 2236;
System.out.println(" [*] Connecting to the server [" + server + ":" + port + "]");
try {
Socket client = new Socket(server, port);
System.out.println(" [+] OK");
while (true) {
// Input
System.out.print("\n [?] Command: ");
Scanner scan = new Scanner(System.in);
String data = scan.nextLine();
data.trim();
// Sending data
System.out.println(" [*] Sending data..." + data);
DataOutputStream output = new DataOutputStream(client.getOutputStream());
output.writeUTF(data);
System.out.println(" [+] OK");
// Receiving data
DataInputStream input = new DataInputStream(client.getInputStream());
data = input.readUTF();
System.out.println(" [*] Receiving data..." + data);
System.out.println(" [+] OK");
// Exit
if (data.equals("exit")) {
System.out.println("\n [*] Closing connection...");
client.close();
break;
}
}
}
catch (IOException e) {
System.out.println(" [!] Error: " + e);
}
}
}
).
/* Server */
import java.net.*;
import java.io.*;
class Server {
public static void main(String[] args) {
System.out.println(" [*] Running server...");
ServerSocket server;
int port = 2236;
try {
server = new ServerSocket(port);
System.out.println(" [+] OK");
System.out.println(" [*] Waiting for clients on port " + server.getLocalPort());
while (true) {
Socket sock = server.accept();
Thread t = new ThreadServerHandler(sock);
t.start();
}
} catch(SocketTimeoutException e) {
System.out.println(" [!] Error: " + e);
} catch (IOException e) {
System.out.println(" [!] Error: " + e);
}
}
}
class ThreadServerHandler extends Thread {
private Socket sock = null;
public ThreadServerHandler(Socket sock) {
super("ThreadServerHandler");
this.sock = sock;
}
public void run() {
try {
System.out.println("\n [+] New client: " + sock.getRemoteSocketAddress());
while (true) {
// Receiving data
DataInputStream input = new DataInputStream(sock.getInputStream());
String data = input.readUTF();
System.out.println("\n [*] Receiving data from " +
sock.getRemoteSocketAddress() + "..." + data);
System.out.println(" [+] OK");
// Exit
if (data.equals("exit")) {
System.out.println("\n [*] Closing connection to host " + sock.getRemoteSocketAddress());
DataOutputStream output = new DataOutputStream(sock.getOutputStream());
output.writeUTF(data);
sock.close();
break;
}
// Running the command
String stdout = runCmd(data);
// Sending data
DataOutputStream output = new DataOutputStream(sock.getOutputStream());
System.out.println(" [*] Sending data to " +
sock.getRemoteSocketAddress() + "...");
output.writeUTF(stdout);
System.out.println(" [+] OK");
}
} catch (IOException e) {
System.out.println(" [!] Error: the connection with host " +
sock.getRemoteSocketAddress() + " has been lost");
}
}
public String runCmd(String cmd) {
try {
String line = null;
StringBuilder builder = new StringBuilder();
builder.append("\n\n");
Process p = Runtime.getRuntime().exec(cmd);
p.waitFor();
BufferedReader stdout = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = stdout.readLine()) != null) {
builder.append(line);
builder.append(System.getProperty("line.separator"));
}
return builder.toString();
} catch (IOException e) {
System.out.println(" [!] Error: " + e);
return "";
} catch (InterruptedException e) {
System.out.println(" [!] Keyboard Interrupt");
return "";
}
}
}/* Client */
import java.net.*;
import java.io.*;
import java.util.Scanner;
class Client {
public static void main(String[] args) {
String server = "127.0.0.1";
int port = 2236;
System.out.println(" [*] Connecting to the server [" + server + ":" + port + "]");
try {
Socket client = new Socket(server, port);
System.out.println(" [+] OK");
while (true) {
// Input
System.out.print("\n [?] Command: ");
Scanner scan = new Scanner(System.in);
String data = scan.nextLine();
data.trim();
// Sending data
System.out.println(" [*] Sending data..." + data);
DataOutputStream output = new DataOutputStream(client.getOutputStream());
output.writeUTF(data);
System.out.println(" [+] OK");
// Receiving data
System.out.print(" [*] Receiving data...");
DataInputStream input = new DataInputStream(client.getInputStream());
data = input.readUTF();
System.out.println(data);
System.out.println(" [+] OK");
// Exit
if (data.equals("exit")) {
System.out.println("\n [*] Closing connection...");
client.close();
break;
}
}
}
catch (IOException e) {
System.out.println(" [!] Error: " + e);
}
}
}/* Server */
import java.net.*;
import java.io.*;
class Server {
public static void main(String[] args) {
System.out.println(" [*] Running server...");
ServerSocket server;
int port = 2236;
try {
server = new ServerSocket(port);
System.out.println(" [+] OK");
System.out.println(" [*] Waiting for clients on port " + server.getLocalPort());
Socket sock = server.accept();
System.out.println(" [+] New client: " + sock.getRemoteSocketAddress());
DataInputStream input = new DataInputStream(sock.getInputStream());
System.out.println(" [*] Receiving data..." + input.readUTF());
System.out.println(" [+] OK");
DataOutputStream output = new DataOutputStream(sock.getOutputStream());
System.out.println(" [*] Sending data...");
output.writeUTF("Visit and join us at http://underc0de.org ;)");
System.out.println(" [+] OK");
sock.close();
}
catch (IOException e) {
System.out.println(" [!] Error: " + e);
}
}
}/* Client */
import java.net.*;
import java.io.*;
class Client {
public static void main(String[] args) {
String server = "127.0.0.1";
int port = 2236;
System.out.println(" [*] Connecting to the server [" + server + ":" + port + "]");
try {
Socket client = new Socket(server, port);
System.out.println(" [+] OK");
DataOutputStream output = new DataOutputStream(client.getOutputStream());
System.out.println(" [*] Sending data...");
output.writeUTF("Hello!");
System.out.println(" [+] OK");
DataInputStream input = new DataInputStream(client.getInputStream());
System.out.println(" [*] Receiving data..." + input.readUTF());
System.out.println(" [+] OK");
client.close();
}
catch (IOException e) {
System.out.println(" [!] Error: " + e);
}
}
}/* Server */
import java.net.*;
import java.io.*;
class Server {
public static void main(String[] args) {
System.out.println(" [*] Running server...");
ServerSocket server;
int port = 2236;
try {
server = new ServerSocket(port);
System.out.println(" [+] OK");
while (true) {
System.out.println(" [*] Waiting for clients on port " + server.getLocalPort());
Socket sock = server.accept();
Thread t = new ThreadServerHandler(sock);
t.start();
}
} catch(SocketTimeoutException e) {
System.out.println(" [!] Error: " + e);
} catch (IOException e) {
System.out.println(" [!] Error: " + e);
}
}
}
class ThreadServerHandler extends Thread {
private Socket sock = null;
public ThreadServerHandler(Socket sock) {
super("ThreadServerHandler");
this.sock = sock;
}
public void run() {
try {
System.out.println(" [+] New client: " + sock.getRemoteSocketAddress());
DataInputStream input = new DataInputStream(sock.getInputStream());
System.out.println(" [*] Receiving data..." + input.readUTF());
System.out.println(" [+] OK");
DataOutputStream output = new DataOutputStream(sock.getOutputStream());
System.out.println(" [*] Sending data...");
output.writeUTF("Visit and join us at http://underc0de.org ;)");
System.out.println(" [+] OK");
sock.close();
}
catch (IOException e) {
System.out.println(" [!] Error: " + e);
}
}
}