WireShark ile localhost'ta (Windows) basit, port yönlendirme tipi bir yakalama yapmak mümkün müdür?
Bunu yapmak için aşağıdaki Java kodunu kullanıyorum:
package tapnet;
import java.net.*;
import java.io.*;
public class tapnet {
public static String getHexString(byte[] buffer, int buflen) {
StringBuffer sb = new StringBuffer();
for (int i=0; i < buflen; i++ ) {
String hexByte = "00" + Integer.toHexString(buffer[i]);
sb.append(hexByte.substring(hexByte.length()-2));
}
return sb.toString();
}
public static void forwardComms(Socket fromClient, Socket toServer) throws Exception {
byte[] buffer;
int buflen;
InputStream clientIn = fromClient.getInputStream();
InputStream serverIn = toServer.getInputStream();
OutputStream clientOut = fromClient.getOutputStream();
OutputStream serverOut = toServer.getOutputStream();
while (true) {
Long waitTime = 0L;
while ((clientIn.available() == 0) && (serverIn.available() == 0)) {
Thread.currentThread().sleep(1);
waitTime = waitTime + 1;
}
System.out.println("QUIET for "+waitTime+" ms");
if (clientIn.available() > 0) {
buflen = clientIn.available();
buffer = new byte[buflen];
clientIn.read(buffer,0,buflen);
System.out.println("CLIENT: "+getHexString(buffer,buflen));
serverOut.write(buffer,0,buflen);
}
if (serverIn.available() > 0) {
buflen = serverIn.available();
buffer = new byte[buflen];
serverIn.read(buffer,0,buflen);
System.out.println("SERVER: "+getHexString(buffer,buflen));
clientOut.write(buffer,0,buflen);
}
}
}
public static void main(String[] args) throws Exception {
if (args.length < 2) {
System.out.println("Usage: tapnet.tapnet <serverPort> <clientPort> [<serverHost>]");
System.exit(1);
}
int serverPort = Integer.valueOf(args[0]);
int clientPort = Integer.valueOf(args[1]);
String serverHost = "127.0.0.1";
if (args.length == 3) {
serverHost = args[2];
}
System.out.println(clientPort + " to " + serverHost + ":" + serverPort);
ServerSocket listenPort = new ServerSocket(clientPort);
while (true) {
Socket fromClient = listenPort.accept();
Socket toServer = new Socket(serverHost,serverPort);
forwardComms(fromClient,toServer);
}
}
}
Ancak WireShark'ı kullanmayı tercih ederim, böylece filtrelemeyi vb. Kullanabilirim.
WireShark'ta benzer bir şeyi nasıl ayarlayabilirim?