我如何知道我的 android 设备上打开了哪些端口以及如何关闭它们?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22271657/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:46:01  来源:igfitidea点击:

How can I know which ports are open on my android device and how to close them?

androidports

提问by QnA_J

Is there an easy way, to see which ports are open on my Android device and a way to close the open ports?

有没有一种简单的方法可以查看我的 Android 设备上打开了哪些端口以及关闭打开端口的方法?

回答by aboujanane

  1. Create a wifi hotspot on your phone
  2. Connect your computer to the hotspot
  3. use ipconfig or ifconfig to know the gateway IP adresse ( ie: your phone's IP adress )
  4. Download nmap : http://nmap.org/
  5. Use the nmap command : nmap -sS -Pn -p- your_phone_ip_adress
  1. 在手机上创建 wifi 热点
  2. 将您的计算机连接到热点
  3. 使用 ipconfig 或 ifconfig 知道网关 IP 地址(即:您手机的 IP 地址)
  4. 下载 nmap:http: //nmap.org/
  5. 使用 nmap 命令:nmap -sS -Pn -p- your_phone_ip_adress

the open TCP ports will be shown as follow :

打开的 TCP 端口将显示如下:



65531 closed ports PORT
STATE SERVICE
53/tcp open domain
8187/tcp open unknown
38647/tcp open unknown
42761/tcp open unknown MAC Address: A4:9A:58:::** (Samsung Electronics Co.)

65531个封闭的端口PORT
STATE SERVICE
53 / TCP开域
8187 / TCP打开未知
38647 / TCP打开未知
42761 / TCP开放未知MAC地址:A4:9A:58: :**(三星电子)



  • PS : For UDP ports use: nmap -sU -Pn -p- your_phone_ip_adress
  • PS:对于UDP端口使用:nmap -sU -Pn -p- your_phone_ip_adress

回答by Chris Stratton

You can determine the currently open ports by reading the textual /proc pseudo-files such as

您可以通过读取文本 /proc 伪文件来确定当前打开的端口,例如

/proc/net/tcp
/proc/net/udp

This is basically what a netstat command (where implemented) does - you may wish to find and examine the source of a simple netstat implementation (it should be possible to port such to java)

这基本上是 netstat 命令(在何处实现)所做的 - 您可能希望找到并检查简单 netstat 实现的来源(应该可以将其移植到 java)

However, when running as an unprivileged app userid, you will only be able to close sockets belonging to your own process (or by roundabout means involving ptrace or process killing, other processes belonging to your userid). Also note that closing a socket does not necessarily make that port available for immediate re-use.

但是,当作为非特权应用程序用户 ID 运行时,您将只能关闭属于您自己进程的套接字(或通过涉及 ptrace 或进程终止、属于您用户 ID 的其他进程的迂回方式)。另请注意,关闭套接字并不一定会使该端口可立即重用。

回答by Prakash

You can try different network commands through runtime and check the results

您可以通过运行时尝试不同的网络命令并检查结果

// netstat -lptu 
// netstat -vat 


Process su = Runtime.getRuntime().exec("netstat -vat ");