美文网首页游戏测试
谁动了你的5037端口

谁动了你的5037端口

作者: 煎煎煎饼 | 来源:发表于2017-12-08 18:41 被阅读44次

许多ADB奇怪的问题,都是源于5037端口被其他程序占用了,经常还是被各种XXX助手软件占用了~

怎么找到占用了5037端口的”元凶“呢?

首先,在CMD下,找到占用端口的进程PID

netstat -ano | findstr 5037 | findstr  LISTENING

TCP    127.0.0.1:5037         0.0.0.0:0              LISTENING       17024

通过这个PID,找到占用的程序

tasklist /FI "PID eq 17024"

映像名称                       PID 会话名              会话#       内存使用
========================= ======== ================ =========== ============
adb.exe                      17024 Console                    1      8,788 K

tasklist是Win下用来显示运行在本地或远程计算机上的所有进程的命令,/FI 是显示一系列符合筛选器指定的进程。

通过程序的名字,找到所在的路径

wmic process where name="adb.exe" get executablepath

ExecutablePath
C:\Android\sdk\platform-tools\adb.exe

最后是kill掉它

taskkill /F /PID 17024

这个过程也可以用Python保存起来,一键运行~

import subprocess
import os

def run_cmd(cmd, shell=True):
    stdout, stderr = subprocess.Popen(cmd, shell=shell, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()

    if stderr:
        print(stderr)
    result = [i.decode('gbk') for i in stdout.splitlines()]
    return result

def is_port_used(port=5037, kill=False):
    """端口占用检测

    :param port: 端口号
    :param kill: 是否kill掉占用端口的进程
    :return:
    """
    cmd = 'netstat -ano | findstr {} | findstr  LISTENING'.format(port)
    print(cmd)
    result = run_cmd(cmd)
    # print(result)
    if result:
        pid = result[0].split()[-1]

        result = run_cmd('tasklist /FI "PID eq {0}"'.format(pid))
        for i in result:
            print(i)

        program_name = result[-1].split()[0]
        print("占用的程序是{}".format(program_name))

        result = run_cmd('wmic process where name="{0}" get executablepath'.format(program_name))
        print("占用的程序所在位置:{}".format(result[2]))

        run_cmd("explorer {0}".format(os.path.dirname(result[2])))  # 打开所在文件夹
        if kill:
            run_cmd("taskkill /F /PID {0}".format(pid))  # 结束进程
    else:
        print('{}端口没有被占用'.format(port))

if __name__ == '__main__':
    is_port_used(kill=False)

相关文章

  • 谁动了你的5037端口

    许多ADB奇怪的问题,都是源于5037端口被其他程序占用了,经常还是被各种XXX助手软件占用了~ 怎么找到占用了5...

  • windows查看端口及端口占用程序

    呼出cmd2.netstat -aon|findstr "5037" 查找5037这个端口被谁占用着3.imag...

  • Android ADB 端口占用问题解决方案

    解决ADB端口占用问题 方式一5037为adb默认端口,若5037端口被占用,查看占用端口的进程PIDC:\Use...

  • adb 5037端口被占用

    方式一 5037为adb默认端口,若5037端口被占用,查看占用端口的进程PIDC:\Users\wwx22949...

  • Android解决ADB端口占用问题

    首先明白一点,5037为adb默认端口。 查看5037端口的进程PID 通过PID查看该进程 杀死占用端口的进程

  • monkey简单使用

    adb 端口占用 adb nodaemon servernetstat -ano | findstr "5037"...

  • adb端口被占用,无法启动问题

    1.查看5037端口被占用进程 netstat -ano | findstr "5037" 罪魁祸首是这个PID为...

  • adb debug

    未识别的主机,当连接91助手之类的也是监听5037端口,所以会出现未识别的主机基本是因为5037端口被占用 2.如...

  • * daemon not running; starting n

    今日使用weeplus run android时 看错误提示 ,是5037端口的问题 于是找到查看端口的 果不其然...

  • Commend

    查看端口占用&杀死进程 netstat -aon|findstr 5037 tasklist /fi "PID e...

网友评论

    本文标题:谁动了你的5037端口

    本文链接:https://www.haomeiwen.com/subject/lcfyixtx.html