Commit 84041751 authored by liuyang's avatar liuyang

抓包结果通过浏览器查看

parent d872cdf0
......@@ -3,19 +3,18 @@ package com.duolebo.blyrobot
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.view.View
import android.widget.Button
import android.widget.Toast
import android.widget.*
import com.duolebo.blyrobot.activity.PackageListActivity
import com.duolebo.blyrobot.data.ApkPackageInfo
import com.duolebo.blyrobot.service.BylWebService
import com.duolebo.blyrobot.util.AppUtil
import com.duolebo.blyrobot.util.Constants
import com.minhui.vpn.ProxyConfig
import com.minhui.vpn.VPNConstants.*
import com.minhui.vpn.service.FirewallVpnService
import com.minhui.vpn.utils.ThreadProxy
import com.minhui.vpn.utils.VpnServiceHelper
import com.minhui.vpn.utils.VpnServiceHelper.START_VPN_SERVICE_REQUEST_CODE
......@@ -53,10 +52,29 @@ class MainActivity : AppCompatActivity() {
selectApp()
}
captureButton = findViewById(R.id.captureButton)
captureButton = findViewById(R.id.captureBtn)
captureButton.setOnClickListener {
runOrStopCapture()
}
val clearBtn = findViewById<Button>(R.id.clearBtn)
clearBtn.setOnClickListener {
clearHistoryData()
}
initCheckbox()
val webUrlText = findViewById<TextView>(R.id.webUrl)
webUrlText.text = "启动抓取后请在浏览器打开:\nhttp://" + AppUtil.getIPAddress(true, null) + ":48080"
}
private fun initCheckbox() {
val checkbox = findViewById<CheckBox>(R.id.videoCheckbox)
val sp = getSharedPreferences(VPN_SP_NAME, Context.MODE_PRIVATE)
checkbox.isChecked = sp.getBoolean(Constants.ONLY_VIDEO, false)
checkbox.setOnCheckedChangeListener { _, isChecked ->
sp.edit().putBoolean(Constants.ONLY_VIDEO, isChecked).apply()
}
}
override fun onResume() {
......@@ -80,7 +98,11 @@ class MainActivity : AppCompatActivity() {
private fun runOrStopCapture() {
if (VpnServiceHelper.vpnRunningStatus()) {
// stopService(Intent(this, BylWebService::class.java))
// 由于5.0以下系统无法控制抓取规则,所以停止抓取之后才能通过web查看
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
stopService(Intent(this, BylWebService::class.java))
}
VpnServiceHelper.changeVpnRunningStatus(this, false)
}
else {
......
package com.duolebo.blyrobot.util
import android.text.TextUtils
import java.io.File
import java.io.FileFilter
import java.net.Inet4Address
import java.net.InetAddress
import java.net.NetworkInterface
import java.util.*
object AppUtil {
fun deleteFile(file: File?, fileFilter: FileFilter) {
......@@ -25,4 +30,35 @@ object AppUtil {
}
file.delete()
}
fun getIPAddress(useIPv4: Boolean, interfaceName: String?): String {
try {
val interfaces = Collections.list(NetworkInterface.getNetworkInterfaces())
for (intf in interfaces) {
if (!TextUtils.isEmpty(interfaceName) && intf.name != interfaceName) {
continue
}
val addrs = Collections.list(intf.inetAddresses)
for (addr in addrs) {
if (!addr.isLoopbackAddress) {
val sAddr = addr.hostAddress.toUpperCase()
// boolean isIPv4 = InetAddressUtils.isIPv4Address(sAddr);
val isIPv4 = addr is Inet4Address //Since API-23 InetAddressUtils was removed
if (useIPv4) {
if (isIPv4)
return sAddr
} else {
if (!isIPv4) {
val delim = sAddr.indexOf('%') // drop ip6 port suffix
return if (delim < 0) sAddr else sAddr.substring(0, delim)
}
}
}
}
}
} catch (ex: Exception) {
}
// for now eat exceptions
return ""
}
}
\ No newline at end of file
......@@ -22,4 +22,7 @@ object Constants {
"ok" to "23",
"back" to "4",
"mute" to "164")
const val ONLY_VIDEO = "only_video"
val VIDEO_EXTS = "m3u8|.ts|.mp4|.rmvb|.mkv|.wmv"
}
\ No newline at end of file
package com.duolebo.blyrobot.web
import android.content.Context
import com.duolebo.blyrobot.util.Constants
import com.minhui.vpn.ProxyConfig
import com.minhui.vpn.VPNConstants
import com.minhui.vpn.VPNConstants.DEFAULT_PACKAGE_ID
......@@ -71,6 +72,7 @@ class CaptureWebServer : NanoHTTPD {
val sp = context.getSharedPreferences(VPNConstants.VPN_SP_NAME, Context.MODE_PRIVATE)
val selectPackage = sp.getString(DEFAULT_PACKAGE_ID, null)
val onlyVideo = sp.getBoolean(Constants.ONLY_VIDEO, false)
while (iterator.hasNext()) {
val next = iterator.next()
if (next.bytesSent == 0 && next.receiveByteNum == 0L) {
......@@ -82,6 +84,11 @@ class CaptureWebServer : NanoHTTPD {
continue
}
if (onlyVideo && !(next.getRequestUrl().contains(".ts") || next.getRequestUrl().contains("m3u8"))) {
iterator.remove()
continue
}
val appInfo = next.appInfo
if (appInfo != null) {
......
......@@ -5,20 +5,43 @@
android:layout_height="match_parent"
android:layout_width="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerInParent="true">
<Button
android:id="@+id/selectBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="选择App抓包"
android:layout_centerInParent="true"/>
android:text="选择目标App"/>
<Button
android:id="@+id/captureButton"
android:id="@+id/captureBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
android:layout_below="@+id/selectBtn"
android:text="开始抓包"/>
<CheckBox
android:id="@+id/videoCheckbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="只抓取视频"/>
<Button
android:id="@+id/clearBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="清除历史"/>
<TextView
android:id="@+id/webUrl"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
\ 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