Commit 68607be4 authored by liuyang's avatar liuyang

tcpdump 抓包http协议连接及退出测试处理

parent b4b71f45
......@@ -27,12 +27,12 @@ class BylRobotService: Service() {
testCapture()
// screenShot()
count++
if (count > 4) {
if (count > 2) {
cancelTimer()
// proc?.destroy()
}
}
},2000, 5*1000)
},2000, 10*1000)
}
private fun screenShot() {
......@@ -52,11 +52,14 @@ class BylRobotService: Service() {
var proc: Process ?= null
private fun testCapture() {
if (proc == null) {
Thread(Runnable {
proc = AdbUtil.tcpCapture("")
}).start()
}
proc?.destroy()
Thread(Runnable {
AdbUtil.killTcpdump()
}).start()
Thread.sleep(3000)
Thread(Runnable {
proc = AdbUtil.tcpCapture("")
}).start()
}
private fun cancelTimer() {
......
......@@ -9,7 +9,7 @@ import java.io.InputStreamReader
object AdbUtil {
const val TAG = "AdbUtil"
const val SHELL = "sh"
const val ROOT_SHELL = "sh"
const val ROOT_SHELL = "su"
const val LINE_BREAK = "\n"
const val EXIT = "exit"
......@@ -174,7 +174,7 @@ object AdbUtil {
}
fun tcpCapture(tcpdump: String): Process? {
val captureCmd = "su\n tcpdump -p -vv -s 0 -A 'tcp dst port 80 and tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x47455420' >> /sdcard/capture.txt\nexit\n"
val captureCmd = "tcpdump -p -vv -s 0 -A 'tcp dst port 80 and tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x47455420' >> /sdcard/capture.txt\n"
val proc = getRootShell()
var dos: DataOutputStream? = null
......@@ -191,7 +191,59 @@ object AdbUtil {
dos?.close()
}
object : Thread() {
override fun run() {
val insBr = BufferedReader(InputStreamReader(proc?.inputStream))
try {
var lineStr: String? = null
do {
lineStr = insBr.readLine()
if (lineStr.isNullOrEmpty())
break
lineStr = trimLine(lineStr)
Log.i(TAG, " tcpdump echo line : $lineStr")
} while (true)
} catch (e: IOException) {
e.printStackTrace()
} finally {
try {
proc?.inputStream?.close()
} catch (e: IOException) {
e.printStackTrace()
}
}
}
}.start()
object : Thread() {
override fun run() {
val errBr = BufferedReader(InputStreamReader(proc?.errorStream))
try {
var errLine: String? = null
do {
errLine = errBr.readLine()
if (errLine.isNullOrEmpty())
break
errLine = trimLine(errLine)
Log.i(TAG, " tcpdump error line : $errLine")
} while (true)
} catch (e: IOException) {
e.printStackTrace()
} finally {
try {
proc?.errorStream?.close()
} catch (e: IOException) {
e.printStackTrace()
}
}
}
}.start()
return proc
}
fun killTcpdump() {
exeCmdEcho("killall tcpdump", true)
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment