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

查看:91
本文介绍了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天全站免登陆