Android:以编程方式确定打开 TCP 连接的应用程序列表 [英] Android: programmatically determine list of apps that have a TCP connection open

查看:16
本文介绍了Android:以编程方式确定打开 TCP 连接的应用程序列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我的 android 上的哪些应用程序连接到哪些 IP 地址.本质上,我想知道这些应用在未经我同意的情况下在后台做什么.

I would like know which applications on my android connect to what IP addresses. In essence I would like to know what these apps do in the background without my approval.

我在我的监控应用程序中尝试了 netstat OS 调用,它已经为我提供了打开的连接和连接的 IP 地址,但是没有进程名称、pid 或 uid 可以让我将连接映射到特定的应用程序.'netstat -p' 似乎没有提供进程信息.

I tried a netstat OS call in my monitoring app, which already gives me the open connections and the connected IP addresses, but there is no process name, pid or uid that would allow me to map a connection to a particular app. 'netstat -p' seems not to provide the process info.

推荐答案

如果你阅读 'netstat' 的源代码,它实际上是从/proc/net/tcp 中读取数据,其中包含 TCP 套接字表的转储,数据会喜欢下面的.

If you read source code for 'netstat', it actually reads data from /proc/net/tcp which holds a dump of the TCP socket table, the data will like below.

sl  local_address rem_address   st tx_queue rx_queue tr tm->when retrnsmt   uid  timeout inode
 0: 0100007F:13AD 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 517 1 cbf19b40 300 0 0 2 -1

您会发现每个连接都有一个 uid,因为 Android 操作系统使用一个用户帐户运行每个应用程序,这意味着拥有一个唯一的 uid,这将有助于将每个连接映射到单个进程.

you will discover each connection has a uid, because Android OS run each application with a user account that means own a unique uid, it will help to map every connection to a single process.

我希望这些信息会有所帮助.

I hope this information will help.

这篇关于Android:以编程方式确定打开 TCP 连接的应用程序列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆