1
0
md/20251016.md
liushuang 2259019410 add
2025-10-16 17:16:39 +08:00

95 lines
3.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 1、下载并上传 openjdk zulu 21 压缩包
- 下载地址https://www.azul.com/downloads/?version=java-21-lts&package=jdk#zulu
- 解压到 /hook/jdk21 目录下
## 2、上传 TShark.java 文件,源码如下
```java
import java.io.*;
import java.nio.file.Path;
import java.time.ZoneId;
import java.util.List;
import java.util.TimeZone;
public final class TShark {
public static void main(String[] args) throws Exception {
TimeZone.setDefault(TimeZone.getTimeZone(ZoneId.of("Asia/Shanghai")));
Path path = Path.of("shark.log");
File sharkLog = path.toFile();
if (!sharkLog.exists() && !sharkLog.createNewFile()) {
throw new RuntimeException("create shark.log failure");
}
// DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
Process process = startSharkProcess();
System.out.println("start tshark success");
startProcessSharkThread(process, sharkLog);
System.out.println("start process thread success");
int exitCode = process.waitFor();
System.out.println("tshark process is dead, exit code: " + exitCode);
}
private static void startProcessSharkThread(Process process, File sharkLog) {
Thread thread = new Thread(() -> {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedWriter fileWriter = new BufferedWriter(new FileWriter(sharkLog, true))) {
String line;
while ((line = reader.readLine()) != null) {
fileWriter.write(line + System.lineSeparator());
}
fileWriter.flush();
} catch (Exception e) {
e.printStackTrace();
}
});
thread.setName("TShark-thread");
thread.start();
}
public static Process startSharkProcess() throws IOException {
List<String> cmd = List.of(
"tshark",
"-l",
"-i",
"\\Device\\NPF_{807C63AC-179D-4AC8-BD56-85CE8AA179DB}",
"-Y",
"tcp.port == 33000 && http.request.method == \"POST\"",
"-V"
);
ProcessBuilder processBuilder = new ProcessBuilder(cmd);
processBuilder.redirectErrorStream(true);
return processBuilder.start();
}
}
```
## 3、修改网卡名称
##### 编辑`TShark.java`文件,找到 **startSharkProcess** 函数
```java
public static Process startSharkProcess() throws IOException {
List<String> cmd = List.of(
"tshark",
"-l",
"-i",
"\\Device\\NPF_{807C63AC-179D-4AC8-BD56-85CE8AA179DB}",
"-Y",
"tcp.port == 33000 && http.request.method == \"POST\"",
"-V"
);
ProcessBuilder processBuilder = new ProcessBuilder(cmd);
processBuilder.redirectErrorStream(true);
return processBuilder.start();
}
```
##### 把这一行网卡名称,替换成正确的网卡名称,下面这个是我自己电脑上的网卡名称
```
"\\Device\\NPF_{807C63AC-179D-4AC8-BD56-85CE8AA179DB}"
```
不确定当前IP使用的哪个网卡可以用下面这个命令查询
```
ip a
```